O'Reilly logo

Mastering Selenium WebDriver by Mark Collin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

FluentWaits – the core of explicit waits

At the core of explicit waits is the incredibly powerful fluent wait API. All the WebDriverWait objects extend FluentWait. So, why would we want to use FluentWait?

Well, we get more granular control over the Wait object, and we can easily specify specific exceptions to ignore. Let's have a look at an example:

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
        .withTimeout(15, TimeUnit.SECONDS)
        .pollingEvery(500, TimeUnit.MILLISECONDS)
        .ignoring(NoSuchElementException.class)
        .withMessage("The message you will see in if a TimeoutException is thrown");

As you can see in the preceding code, we created a wait object with a 15-second timeout that polls every five hundred milliseconds to check whether a condition ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required