9

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 ?

SK176H
  • 1,319
  • 3
  • 14
  • 25

5 Answers5

5

2 years later, ruby implementation:

wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.util {
  @driver.execute_script("return document.readyState;") == "complete" 
}
itsjeyd
  • 5,070
  • 2
  • 30
  • 49
allenhwkim
  • 27,270
  • 18
  • 89
  • 122
3

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.

Eric Andres
  • 3,417
  • 2
  • 24
  • 40
bemcho
  • 39
  • 2
  • Is this a new class? I've got 2.39 (of the c# bindings) and it doesnt seem to be there. What dll does this come from? Maybe I'm missing one – JonnyRaa Jan 27 '14 at 17:07
0

I think with selenium 2, you don't need to wait after a form submit using Firefox webdriver.

     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 content is loaded by javascript after the page is loaded, 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]")); //
surajz
  • 3,471
  • 3
  • 32
  • 38
  • Whether Selenium 2 will wait after the `click()` depends on how the page is loaded. – reinierpost Aug 14 '12 at 12:45
  • I think an exception will throw you out of the time loop. I don't think this would work. You need to use a WebDriverWait with the .ignoring method. – djangofan Mar 12 '13 at 17:08
-2

http://release.seleniumhq.org/selenium-remote-control/0.9.0/doc/java/

waitForpageLoad()

Rizwan Sharif
  • 1,089
  • 2
  • 10
  • 20
  • I guess waitForPageLoad is used when you are using selenium RC. whats the case with Webdriver ? I am using Firefox driver .... i did some try and error and it seems that there is no need to write anything whenever we submit a form . can someone please comment – SK176H May 30 '11 at 15:07
  • See http://stackoverflow.com/questions/10720325/selenium-webdriver-wait-for-complex-page-with-javascript-to-load – reinierpost Aug 14 '12 at 12:46
-2
for (int second = 0;; second++) {
            if (second >= 60) fail("timeout");
            try { if (isElementPresent(By.linkText("element"))) break; } catch (Exception e) {}
            Thread.sleep(1000);
        }
Marouane Gazanayi
  • 5,063
  • 6
  • 39
  • 58