There are following waits:
FluentWait
This is special wait where You can set time to wait for a certain condition, as well as the frequency with which to check the condition like eg. wait for 10s and check every 1s, and ignore "NoSuchElementExceptions" exception, if You anticipate that this exception will happen for some time.
Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(new Function() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
});
Explicit wait
It is kind of wait where You can set it up to wait for any condition you might like. Usually, you can use some of the prebuilt ExpectedConditions
Types of Expected Conditions:
https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/support/ui/ExpectedConditions.java
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
Implicit wait
wait for element, until exception is thrown while initialising object, and its defined through entire session
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.get("http://...");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));
PageLoadTimeout
How long it will until page is loaded:
driver.manage().timeouts().pageLoadTimeout(100, SECONDS);
SetScriptTimeout
If you have asynch scripts. Time to wait for an asynchronous script to finish execution before throwing an error.
driver.manage().timeouts().setScriptTimeout(100,SECONDS);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…