Make Selenium Easy

FluentWait Vs WebDriverWait in Selenium WebDriver

FluentWait Vs WebDriverWait” , A hot topic in Selenium WebDriver but still confuses many. Let’s see if I can help you to understand the difference between these two.

Class WebDriverWait is a disciplined child (Specialization) of Class FluentWait and grand child of interface Wait. In short, Class FluentWait implements Wait interface and WebDriverWait extends FluentWait.

So there are many things common in WebDriverWait and FluentWait instances such as :-

  1. You can set polling interval in both instances.
  2. You can ignore any exceptions in both instances.
  3. You can use ExpectedConditions methods in both instances.
  4. You can override apply() method in both instances.

This I have tried to explain in WebDriverWait & FluentWait in Selenium WebDriver – Let’s Deep Dive.

Are you thinking that If they are common then why WebDriverWait is given? We could have used FluentWait itself.

That is a valid doubt. But the major difference between them is that WebDriverWait is a specialization of FluentWait which uses WebDriver instance and this class have added specific mechanism related to WebDriver.

Do you believe in learning differences from example? Let’s try it.

I have created a basic html page where an element is visible after some time. I will implement both FluentWait and WebDriverWait to wait for element to be displayed. We can use Implicit wait as well but for this example, we will not consider that. Anyway implicit wait should be ignored because at many places in scripts we unknowingly mix waits which is not a good practice and can get unexpected result.

HTML Code :-

Selenium WebDriver code with FluentWait :-

Output :-

Selenium WebDriver code with WebDriverWait :-

Output :-

Did you notice that when we used WebDriverWait, WebDriver waits for element to be present and does not throw NoSuchElementException which happened in FluentWait example ? You got it. That is a major difference between FluentWait and WebDriverWait.

FluentWait is a generic class and WebDriverWait is its specialization class with WebDriver instance. Since WebDriverWait is specialization class of FluentWait class, it ignores instances of NotFoundException that are encountered (thrown) by default in the ‘until’ condition, and immediately propagate all others.

NotFoundException is a sub class of WebDriverException and NoAlertPresentExceptionNoSuchContextExceptionNoSuchCookieExceptionNoSuchElementExceptionNoSuchFrameExceptionNoSuchWindowException are direct sub classes of it. So in above example we already saw that WebDriverWait instance ignored NoSuchElementException. In fact it will ignore other mentioned exception by default which is not in case of FluentWait. If you need to ignore any exception in FluentWait instance, you need to mention it explicitly as below :-

Output will be same as WebDriverWait.

Some myths about FluentWait and WebDriverWait :-

  1. FluentWait allows to set polling interval while WebDriverWait does not. Fact – You can set in both after all WebDriverWait extends FluentWait and all configurable methods are public in FluentWait.
  2. We can not use conditions defined in class ExpectedConditions in FluentWait instance and override apply method in WebDriverWait instance. Fact – You can use any one in any instance.

WebDriverWait is a ready to use class for WebDriver. WebDriverWait can not be used for a non-selenium waiting condition while FluentWait can be used.

I have covered FluentWait in much details on my blog. You can find the details below:-

How to Fluent With FluentWait in Selenium WebDriver? – Part 1

How to Fluent With FluentWait in Selenium WebDriver? – Part 2

You can clone the above example from my repo.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

Table of Contents

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

1 thought on “FluentWait Vs WebDriverWait in Selenium WebDriver

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.