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)
The script timeout error is a WebDriver error that occurs when a script the user has provided did not complete before the session’s script timeout duration expired. The script timeout duration is a configurable capability, which means you can change how long it will take before the driver interrupts an injected script.
S tarting with version 60, the Chrome browser introduced the ability to run in headless mode. We now have the ability to launch the browser without creating a visual browser window. This will allow you to run tests faster and with fewer resources, and most importantly, it will allow you to run tests on systems without a graphical component.
ScriptTimeoutException as e: print( e. message) However, it is possible to extend the session’s default script timeout by using capabilities if you have a script that you expect will take longer: from selenium import webdriver from selenium. common import exceptions session = webdriver.
Headless test automation execution simulates the actual actions as they were preformed on an actual browser, but it doesn’t require any GUI. By running tests in a Headless mode you will also notice much faster performance – tests that run in a headless mode run 2 to 10 times faster than running in a normal mode browser.
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!
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With