Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i wait for a page to load after a form submits in Webdriver. I am using firefox driver

Tags:

webdriver

I am trying to automate a test case where i submit the form by clicking on an image.

After the page reloads i am not able to interact with any element on the webpage

I am using java , firefox driver.

The code gets stuck and is not able to identify the element at all.

Is there any wait mechanism with webdriver like there is with QTP , selenium ?

like image 508
SK176H Avatar asked May 30 '11 01:05

SK176H


2 Answers

2 years later, ruby implementation:

wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.util {
  @driver.execute_script("return document.readyState;") == "complete" 
}
like image 68
allenhwkim Avatar answered Oct 15 '22 23:10

allenhwkim


Just use FluentWait class:

/**
 * An implementation of the {@link Wait} interface that may have its timeout
 * and polling interval configured on the fly.
 *
 * <p>Each FluentWait instance defines the maximum amount of time to wait for
 * a condition, as well as the frequency with which to check the condition.
 * Furthermore, the user may configure the wait to ignore specific types of
 * exceptions whilst waiting, such as
 * {@link org.openqa.selenium.NoSuchElementException NoSuchElementExceptions}
 * when searching for an element on the page.
 *
 * <p>Sample usage:
 * <code><pre>
 *   // Waiting 30 seconds for an element to be present on the page, checking
 *   // for its presence once every 5 seconds.
 *   Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
 *       .withTimeout(30, SECONDS)
 *       .pollingEvery(5, SECONDS)
 *       .ignoring(NoSuchElementException.class);
 *
 *   WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
 *     public WebElement apply(WebDriver driver) {
 *       return driver.findElement(By.id("foo"));
 *     }
 *   });
 *

or WebDriverWait.

like image 22
bemcho Avatar answered Oct 15 '22 22:10

bemcho