Fluentwait in selenium Webdriver and Different usage in Selenium

Wait in Selenium Webdriver is one of the most important topics for real-time applications and for interviews as well. Fluentwait in selenium webdriver in one of the examples of the dynamic wait which will solve many sync issues in Selenium Webdriver.

 

There are many kinds of wait available in Selenium which are

fluentwait in selenium webdriver

Fluentwait in selenium webdriver is one of the most versatile wait which will give you the complete power to handle any kind of situation based on your requirement.

 

Why wait is required

1-Now a day many applications are using AJAX control, Jquery and many other complex widgets which make application slow and data takes some time to appear on screen so we need to wait until data is not present on UI.

2-When you perform the complex operation on any application it also takes some time for processing and we have to make sure our script should wait until specific conditions are not true.

 

There are much more examples in which we have to apply wait so that our script should not fail and we can get good ROI (Return of investment).

 

Definition of Fluentwait in selenium webdriver

In simple words, Fluent wait is just a plain class and using this class we can wait until specific conditions are met.

In Fluent wait, we can change the default polling period based on our requirement.

 

Technical details

1-Fluent wait is a class and is part of org.openqa.selenium.support.ui Package

2-It is an implementation of Wait interface.

3-Each fluent wait instance defines the maximum amount of time to wait for a condition and we can give the frequency with which to check the condition.

4- We can also ignore any exception while polling element such as NoSuchElement exception in Selenium.

 

Now we have discussed enough on Fluent wait and its usage so let’s talk about the implementation part of it and how we can use in our project or in our framework.

 

You will also get questions in your interviews that what is the difference between explicit wait and Fluent wait.

Ans- In explicit wait, you can use some set of existing precondition to wait like

Wait till element is not visible, wait till element is not clickable, Wait till presence of element located and so on.

 In Fluent wait, you can customize the apply method and you can write your own conditions based on your requirement.

 

Note- 95 % of your test can be handled via explicit wait and in some cases, you have to use Fluent wait so it totally up to you.

 

Syntax of Fluentwait in selenium webdriver

Fluentwait in selenium webdriver

 

// Waiting 60 seconds for an element to be present on the page, checking

// for its presence once every 2 seconds.

 

As you can see the syntax is quite complex but we don’t have to worry about that because we have to change only Apply method which will make our task easy.

FluentWait in Selenium Webdriver

 

Requirement-

1- Click on timer

2- Wait till the WebDriver text is not coming.

3- Once WebDriver appears- Stop the wait and print the status.

 

Complete program of Fluentwait in selenium webdriver

 

Final thoughts- The same requirement can be fulfilled via explicit wait so its up to you which one to prefer. I would recommend you to create a library for this and you can use whenever it’s required.

In my org, we have created a custom library which takes care of Sync issue and we have to use less explicit wait and fluent wait of Selenium Webdriver.

You can try this wait with multiple scenarios and it’s up to you. In case if you have any thoughts related to this then don’t hesitate to share. Let me know the same in the comment section and if you find this article helpful then feel free to share with your friends as well.

 

 

6 Comments

  1. Bobby
  2. Subhani

Leave a Reply