Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent Wait and WebDriver Wait - Differences

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?

like image 702
Satish Avatar asked Nov 11 '13 14:11

Satish


People also ask

What is the difference between the fluent wait and the WebDriver wait?

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”.

What are the three types of wait in Selenium?

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().

What is the difference between the implicit wait and WebDriverWait?

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.

What is a fluent wait?

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.


1 Answers

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")));
like image 196
nilesh Avatar answered Sep 30 '22 00:09

nilesh