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 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 in the ignoring
method. We also want...