Sometimes when i run a test, website never stops loading and my test stucks on it. How can i set driver.get() method to not wait for page load? If its impossible are there any work arounds or other methods that could replace driver.get()?
The easiest way to exit the page load wait early is to set the page load timeout. When the timeout expires, you can catch the TimeoutException
and proceed with the next step of your test. The code to invoke this would look something like the following:
// Set the page load timeout to 10 seconds.
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
try {
driver.get("http://url/to/my/slow/loading/page");
} catch (TimeoutException e) {
// Ignore the exception.
}
// Proceed with your next step here.
Note that you may have to use a WebDriverWait
or similar to ensure the element you're interested in is present on the page.
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