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 {
} 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(“”);
js.executeScript(“window.location.href = ‘'”);

Leave a Reply

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