Explicit wait in Selenium Webdriver and How to Implement

To understand the Explicit wait in Selenium Webdriver you should know the requirement why we use wait statement in programs. I will give you a couple of examples in which you will get the complete idea why wait is important.

 

Condition for Explicit wait in selenium webdriver

Condition 1- I have a web page which has some login form and after login, it takes a lot of time to load Account page or Home page. This page is dynamic it means sometimes it takes 10 seconds to load the homepage, sometimes its 15 second and so on. In this situation, the Explicit wait can help us which will wait until specific page/page title is not present it will keep waiting.

 

Condition 2- You are working on travel application and you have filled the web form and clicked on submit button. Now you have to wait until complete data is not loaded or specific data is not loaded. In this case, again we can use Explicit wait in which we can give wait till specific or set of elements are not loaded.

 

Condition 3- There are some elements on a web page which are hidden and it will be displayed only when specific conditions get true, so we have to wait until these elements are not visible. In this case, again explicit wait will help in which we can specify wait till the element or elements are not visible.

Explicit wait in selenium webdriver

 

The good thing which will make you happy is that you don’t have to write code for all these conditions. It is already defined in a separate class and we just have to use them based on our requirement.

ExpectedConditions is a class in Selenium which has some predefined condition which makes our task easy.

explicit-wait-in-selenium

 

What is Explicit wait in selenium webdriver

It is a concept of the dynamic wait which wait dynamically for specific conditions. It can be implemented by WebDriverWait class.

 

Syntax of Explicit wait in selenium webdriver

 

Now you must be confused between Implicit wait and Explicit wait right?

Don’t worry its totally different let me make it clear for you with the help of one example.

Implicit wait– It only checks the presence of element on WebPage that’s all if elements are hidden or any other condition then it will not handle and it will fail your script.

It is applicable for all the element after initialization.

Explicit wait– It has so much capability which we already discussed and it is applicable to the specific element.

We have one more wait which is FluentWait which is more advance is nature. In interviews, you will definitely get this questions very frequently that what is the difference between Implicit wait,Explicit wait and Fluent Wait in Selenium Webdriver.

 

Note- We can use implicit wait and explicit wait in the single script.

 

                                                       Youtube video for Explicit Wait 

 

Program for Explicit waits in selenium webdriver

 

I hope it must be clear for you regarding dynamic wait in Selenium and when to use which wait in Selenium. If you have any thoughts in mind then let me know in the comment section.

Happy Testing 🙂

22 Comments

  1. Manjeet
  2. sowji
  3. Vignesh
  4. Sachin Patil
  5. sowjanya
      • Soumen
  6. Vipin
  7. Amod Mahajan
  8. Shreyansh Jain

Leave a Reply