Skip to main content
blog title image

2 minute read - Selenium WebDriver FAQs Test Automation

How to Use a Fluent Wait DSL

Jul 1, 2020

Earlier versions of WebDriver used a FluentWait class, the WebDriverWait now offers a fluent DSL approach for configuring the wait.

My synchronisation strategies with WebDriver have generally revolved around the WebDriverWait and creating custom ExpectedCondition objects.

A traditional basic use of WebDriverWait uses minimal customisation, because most of the defaults are good enough for our use.


WebDriverWait wait = new WebDriverWait(driver, 10);

Fluent Interface

A basic wait, is already fluent and we can chain the methods:

new WebDriverWait(driver, 10)

This doesn’t mean that the code is easier to read or maintain, because it might be better to re-use the wait later in the test.

But the fluent interface allows us to use code completion to build it up.

The fluent interface goes beyond the simple use case allowing us to configure the wait.


WebDriverWait extends a FluentWait class.

FluentWait can be useful for waiting on ‘anything’ and we cover that in our Synchronisation Course.

Allowing us to chain methods to configure

  • withTimeout how long before timeout
  • withMessage the message to display when it timesout
  • pollingEvery how long between polling intervals
  • ignoreAll, ignoring which exceptions to ignore during the polling

All of the above methods can be ‘chained’ to create a fluent configuration of a WebDriverWait


The code waits for the element to become visible using a WebDriverWait then drops down to a lower level of granularity to check that the seconds count down to 04


By countdown ="javascript_countdown_time");

WebDriverWait wait = new WebDriverWait(driver,10);

wait.until( ExpectedConditions.

                countdown, Pattern.compile(".*:04$")) );

The additional configuration offered by Fluent configuration of a WebDriverWait can prove pretty handy for Ajax because of the flexibility you have for ignoring exceptions and easily tweaking the wait and polling times.

Full Source

The full source for this is in my Webdriver Java FAQs project:


If you want to learn how to use Selenium WebDriver with Java then check out our online courses. And we have a whole course on effective synchronisation strategies.