Selenium WebDriver get(url) speed issue Selenium WebDriver get(url) speed issue selenium selenium

Selenium WebDriver get(url) speed issue


You can use Page load timeout. As far as I know, this is definitely supported by FirefoxDriver and InternetExplorerDriver, though I'm not sure about other drivers.

driver.manage().timeouts().pageLoadTimeout(0, TimeUnit.MILLISECONDS);try {    driver.get("http://google.com");} catch (TimeoutException ignored) {    // expected, ok}

Or you can do a nonblocking page load with JavaScript:

private JavascriptExecutor js;// I like to do this right after driver is instantiatedif (driver instanceof JavascriptExecutor) {    js = (JavascriptExecutor)driver;}// later, in the test, instead of driver.get("http://google.com");js.executeScript("window.location.href = 'http://google.com'");

Both these examples load Google, but they return the control over the driver instance back to you immediatelly instead of waiting for the whole page to load. You can then simply wait for the one element you're looking for.


In case you didn't want this functionality just on the WebDriver#get(), but on you wanted a nonblocking click(), too, you can do one of these:

  1. Use the page load timeout as shown above.
  2. Use The Advanced User Interactions API (JavaDocs)

    WebElement element = driver.findElement(By.whatever("anything"));new Actions(driver).click(element).perform();
  3. Use JavaScript again:

    WebElement element = driver.findElement(By.whatever("anything"));js.executeScript("arguments[0].click()", element);