1

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?

Jacek Wojcik
  • 1,223
  • 2
  • 19
  • 33
  • I'm not sure what language you're using, but all of the bindings as far as I know have a **WebDriverWait** object where you can wait for whatever you want and give it a timeout. Once the timeout is reached, it will throw an error. In short, the answer is yes, use **WebDriverWait**. – mrfreester Dec 05 '17 at 17:02
  • But will I get a detailed error with name of a link which takes too long? – Jacek Wojcik Dec 05 '17 at 17:26
  • 1
    Yes, if you program it that way. **WebDriverWait** is pretty customizable. – mrfreester Dec 05 '17 at 17:38

1 Answers1

1

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.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352