Timeout Error occurred When run a script on Headless chrome browser by using Selenium Webdriver with Python

纵然是瞬间 提交于 2021-01-20 20:23:26

问题


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

Stack trace:

 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) 

回答1:


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.

I hope this helps!




回答2:


I faced same issue and was able to resolve it after updating my chromedriver and adding chrome_options.add_argument("--window-size=1920,1080") to the chrome options. The options I currently apply are:

chrome_options = Options()  
chrome_options.add_argument("--headless") 
chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument('disable-infobars')


来源:https://stackoverflow.com/questions/45798842/timeout-error-occurred-when-run-a-script-on-headless-chrome-browser-by-using-sel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!