Satish
Satish

Reputation: 752

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?

Upvotes: 8

Views: 11566

Answers (1)

nilesh
nilesh

Reputation: 14289

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")));

Upvotes: 11

Related Questions