I have seen both FluentWait
and WebDriverWait
in code using Selenium. FluentWait
uses a Polling Technique i.e. it will be poll every fixed interval for a particular WebElement
. I want to know what Does WebDriverWait
do with ExpectedConditions
?
Consider following Java example:
WebDriverWait wait = new WebDriverWait(driver, 18);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Account")));
WebElement element = driver.findElement(By.linkText("Account"));
element.sendKeys(Keys.CONTROL);
element.click();
Does ExpectedConditions.elementToBeClickable(By.linkText("Account"))
monitor for linkText("Account")
to be clickable or does it wait 18 seconds before clicking?
Fluent Wait in Selenium marks the maximum amount of time for Selenium WebDriver to wait for a certain condition (web element) becomes visible. It also defines how frequently WebDriver will check if the condition appears before throwing the “ElementNotVisibleException”.
There are three types of waits in selenium. Implicit wait, explicit wait and fluent wait. Implicit wait: Once you define implicit wait then it will wait for all findElement() and findElements().
Implicit wait specifies a time to wait for the lifetime of WebDriver and is applicable for each element i.e. done once. Explicit waits, however, depend on the conditions. The explicit wait depends on the specified condition or the maximum duration of allowed time for waiting.
An implementation of the Wait interface that may have its timeout and polling interval configured on the fly. 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.
In your example wait.until(ExpectedConditions...)
will keep looking (every 0.5s) for linkText
'Account' for 18 seconds before timing out.
WebDriverWait
is a subclass of FluentWait<WebDriver>
.
In FluentWait
you have more options to configure, along with maximum wait time, like polling interval, exceptions to ignore etc. Also, in your code, you don't need to wait and then findElement
in the next step, you could do:
WebElement element = wait.until(
ExpectedConditions.elementToBeClickable(By.linkText("Account")));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With