This is the first time I use selenium and headless browser as I want to crawl some web page using ajax tech.
The effect is great, but for some case it takes too much
As you mentioned in your question it takes too much time to load the whole page(especially when some resource is unavailable) is pretty much possible if the Application Under Test (AUT) uses JavaScript or AJAX Calls.
set_page_load_timeout(5)
and set_script_timeout(5)
execute_async_script
call before throwing an exception.Hence the Application Under Test being dependent on JavaScript or AJAX Calls in presence of both the conditions raises TimeoutException.
In your second scenario you have induced both implicitly_wait(2)
and WebDriverWait(driver, 2, 0.5)
.
WARNING : Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example setting an implicit wait of 10 seconds and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds.
The best solution would be to remove all the instance of implicitly_wait(time_to_wait)
and replace with WebDriverWait()
for a stable behavior of the Application Under Test (AUT).
As per your counter question, the current code block looks perfect. The measurement of time which you are seeing as time used: 44.6049938202 s
is the time required for the Web Page to load completely and functionally that is the time required for the Client (i.e. the Web Browser) to return back the control to the WebDriver instance once 'document.readyState' equals to "complete" is achieved. Selenium or as an user you have no control on this rendering process. However for a better performance you may follow the best practices as follows :