通过将Selenium Webdriver与Python结合使用在Headless chrome浏览器上运行脚本时发生超时错误 [英] Timeout Error occurred When run a script on Headless chrome browser by using Selenium Webdriver with Python

查看:209
本文介绍了通过将Selenium Webdriver与Python结合使用在Headless chrome浏览器上运行脚本时发生超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行python脚本以测试 Headless Chrome Broswer(Webdriver + Selenium )上的网站时,我们经常会遇到超时错误,我发现该问题是通过.click().send_keys()方法.谁能知道这是什么问题?有时工作正常,但有时会出现超时错误.请给出相同的解决方案

When I am running python scripts to test a website on Headless Chrome Broswer (Webdriver + Selenium), we often get a timeout error, I found out the problem occurred when script interacted with browser by .click() or .send_keys() methods. Can anyone know what the kind of problem it is? Sometimes it is working fine but sometimes I have got timeout error. Please give a solution for the same

堆栈跟踪:

 15:01:48,194 root:ERROR: ERROR occurred: Message: timeout
   (Session info: headless chrome=60.0.3112.101)
   (Driver info: chromedriver=2.31.488763 
   (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 6.1.7601 SP1 
    x86)

    Traceback (most recent call last):
  File "c:\autotest\x.py", line 148, in main
    func(nik)
  File "c:\autotest\lib\support.py", line 126, in wrapper
    raise ret
  File "c:\autotest\lib\support.py", line 113, in newFunc
    res[0] = func(*args, **kwargs)
  File "c:\autotest\testcases\1001.py", line 15, in testcase
    "documents_approved ASC", generateError=True)  
  File "c:\autotest\lib\support.py", line 51, in wrapper
    f_result = func(*args, **kwds)
  File "c:\autotest\pageobjects\web\segment_header.py", line 184, in login
    + Keys.ENTER)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 350, in send_keys
    'value': keys_to_typing(value)})
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 499, in _execute
    return self._parent.execute(command, params)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
    self.error_handler.check_response(response)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: timeout
  (Session info: headless chrome=60.0.3112.101)
  (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 6.1.7601 SP1 
    x86) 

推荐答案

我遇到了类似的问题,普通的Chrome驱动程序工作正常,但无头Chrome总是超时.

I was having a similar problem, normal Chrome driver worked fine, but headless chrome always timed out.

我发现对于自适应网页,您需要设置窗口大小:

I found out that for responsive web pages, you need to set the window size:

driver.set_window_size(1200, 600)

在驱动程序本身初始化后添加此行之后,它起作用了.

It worked after adding this line just after initialization of the driver itself.

我希望这会有所帮助!

这篇关于通过将Selenium Webdriver与Python结合使用在Headless chrome浏览器上运行脚本时发生超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆