How to wait for a page to load after submitting a form to Webdriver. I am using the firefox driver

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

After reloading the page, I cannot interact with any element on the web page.

I am using java driver, firefox.

The code is stuck and cannot identify the item at all.

Is there a wait mechanism with webdriver similar to QTP, selenium?

+8
webdriver
source share
5 answers

Just use the 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 .

+3
source share

2 years later, ruby โ€‹โ€‹implementation:

 wait = Selenium::WebDriver::Wait.new(:timeout => 10) wait.util { @driver.execute_script("return document.readyState;") == "complete" } 
+3
source share

I think that with selenium 2 you do not have to wait after submitting the form using the Firefox web browser.

  element.sendKeys("34344343"); webDriver.findElement(By.id("searchSubmitButton")).click(); WebElement columnInPostedPage = webDriver.findElement(By.xpath("//div[@id='content']/table/tbody/tr[2]/td[3]")); // 

If the content is loading javascript after the page loads, you can do something like this for the content

  query.submit(); long end = System.currentTimeMillis() + 5000; while (System.currentTimeMillis() < end) { WebElement result = webDriver.findElement(By.id("content")); if (result.isDisplayed()) { break; } //Thread.sleep(1000); } WebElement columnInPostedPage = webDriver.findElement(By.xpath("//div[@id='content']/table/tbody/tr[2]/td[3]")); // 
0
source share
 for (int second = 0;; second++) { if (second >= 60) fail("timeout"); try { if (isElementPresent(By.linkText("element"))) break; } catch (Exception e) {} Thread.sleep(1000); } 
-one
source share
-2
source share

All Articles