Fluent waits, the core of explicit waits
At the core of explicit waits is the incredibly powerful fluent wait API. All WebDriverWait
objects extend FluentWait
. So, why would we want to use FluentWait
?
Well, we get more granular control of the wait
object, and we can easily specify exceptions to ignore. Let's have a look at an example:
Wait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(15)) .pollingEvery(Duration.ofMillis(500)) .ignoring(NoSuchElementException.class) .withMessage("The message you will see in if a TimeoutException is thrown");
As you can see, in the preceding code snippet, we have created a wait
object with a 15-second timeout that polls every 500 milliseconds to see whether a condition is met. We have decided that while waiting for our condition to become true, we want to ignore any instances of NoSuchElementException
, so we have specified it using the .ignoring()
command. We also want to return...