Website I am testing needs to load libraries from xxxx
server.
Sometimes it takes to long and website display information Waiting for xxxx
(I am using Chrome WebDriver).
Is it possible to treat it as an error and catch it using Selenium?
Website I am testing needs to load libraries from xxxx
server.
Sometimes it takes to long and website display information Waiting for xxxx
(I am using Chrome WebDriver).
Is it possible to treat it as an error and catch it using Selenium?
Sometimes when it takes to long and you see website display information Waiting for xxxx
it is not actually an error. It means the the JavaScripts
and the AJAX Calls
associated with the Website are getting executed while the Page Loads
. Once the JS
& AJAX Calls
gets executed completely, the Page Loading completes.
Now as per your question Is it possible to treat it as an error and catch it?
the Answer is Yes
.
This can be achieved by using the pageLoadTimeout
method which Sets the amount of time to wait for a page load to complete before throwing an error.
Defined as pageLoadTimeout(long time, java.util.concurrent.TimeUnit unit)
, an example will be as follows :
driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS);
The error thrown is as follows :
Exception in thread "main" org.openqa.selenium.TimeoutException: Timeout loading page after 2000ms
You can find a detailed implementation of pageLoadTimeout
in pageLoadTimeout in Selenium not working
discussion.