The page you pointed is not just static HTML - it invokes a CGI script after submitting the form. It looks like your test sometimes proceeds to iterating over the table elements assuming submit returns after the new page, with the results of the CGI script, loads. While that behaviour is desired, it's hard to guarantee, which is why we recommend checking for specific state of a page after interactions with the page that change it or load a new one.
Patrick
driver.manage().timeouts().implicitlyWait();
The implicit waits cause "findElement" to wait up to the expected time
limit for an element to be present before throwing an exception, and
"findElements" to wait until the list of returned elements is not
empty or the time limit is exceeded.
Although implicit waits can make code look clearer, they also hide the
intent of the test. Using the Wait interface is pretty easy:
Wait<WebDriver> wait = new WebDriverWait(driver, 5);
WebElement element = wait.until(elementIsVisible(By.id("fish"));
Where "elementIsVisible" is defined as:
public ExpectedCondition<WebElement> elementIsVisible(
final By locator) {
return new ExpectedCondition<WebElement>() {
public WebElement apply(WebDriver driver) {
WebElement e = driver.findElement(locator);
if ((RenderedWebElement) e).isDisplayed()) {
return e;
}
return null;
}
}
}
Simon
Feel free to raise a bug about this so it doesn't drop of the radar of
"Things To Check Out"
Simon
Simon