I'm writing automated tests using Selenium WebDriver and Java that need lots of waits in them to make sure that the appropriate element has loaded before the next action is taken.
I've tried this:
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
which will wait for a specified interval and then fail if the element is not found, and this:
WebDriverWait wait = new WebDriverWait(driver, 100);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver webDriver) {
System.out.println("Searching for the Companies dropdown");
return webDriver.findElement(By.id("ctl00_PageContent_vpccompanies_Input")) != null;
}
});
which will hang indefinitely if the element is not found.
What I'd like is something that would search for the element for a couple of tries and then fail with an error message.