Friday, 25 March 2016

What is fluent wait in Selenium Webdriver

Fluent wait is used to synchronize the elements in the browser.

Fluent wait allows you to
  1. Specify polling time
  2. Maximum time out
  3. Ignore Exceptions
Consider a scenario wherein you are expecting specific element to appear within 20 seconds. Time to load that element might change from 5 seconds to 20 seconds. In this situation, we can use Fluent Wait as mentioned in below example.

public void testWait(){
  String driverpath = 
  driver = new ChromeDriver();
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

  Wait wait = new FluentWait(driver)
            .withTimeout(20, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS)

  WebElement foo =(WebElement) wait.until(
   new Function<WebDriver, WebElement>() {
   public WebElement apply(WebDriver driver) {
   return driver.findElement(By.xpath("//input[@value='Sign up']"));


Above code will wait until element with xpath //input[@value='Sign up'] is found. The code will wait for 20 seconds maximum and throw exception at the end if element is not found even after 20 seconds.

What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at

No comments:

Post a Comment

Buy Best Selenium Books