Non-blocking Page Loading

By default WebDriver blocks till page is fully loaded when driver.get(URL) is executed. Most time this is what we desired but sometimes we want to change this behavior:

  • We just want to check something on the page, without waiting for slow image-loading
  • Sometimes our app’s third-party tracking request hangs, causing our automation from going forward, but we want to ignore the request-hanging for now and check other user-related features

We can specify the maximum time we want to wait for page to load using Page load timeout.

driver.manage().timeouts().pageLoadTimeout(0, TimeUnit.MILLISECONDS);
try {
driver.get(“http://www.automeditator.com”);
} catch (TimeoutException ignored) {
// timed out as expected, ok
}

Or we can do a non-blocking page load with JavaScript:

private JavascriptExecutor js;
// I like to do this right after driver is instantiated
if (driver instanceof JavascriptExecutor) {
js = (JavascriptExecutor)driver;
}
// later, in the test, instead of driver.get(“http://www.automeditator.com”);
js.executeScript(“window.location.href = ‘http://www.automeditator.com'”);

Leave a Reply

Your email address will not be published. Required fields are marked *