Custom library to solve Synchronization in Selenium Webdriver

Today in this post, I will show you how to handle Synchronization in Selenium Webdriver. I am 200% sure that you are also not happy with the wait provided by Selenium, which does not serve our purpose.
Selenium has less number of sync method which actually makes your Selenium script unstable and most of the time Selenium scripts fails only for synchronization. Please check official wait classes provided by Selenium for sync issues.

Different type of Wait in Selenium

 

What is Synchronization in Selenium Webdriver

Every application now days contains some AJAX call which receives the response from the server then it displays on an application.
You must have tried implicit wait, explicit wait and fluent wait in Selenium but as per my experience, it does not full fill my requirement. If you have ever thought of how it works then you must be having one thing in mind it checks the element in DOM and it returns the element or it will throw an exception.

 

Solution for Synchronization in Selenium Webdriver

Recently I created a small method, which actually does the same thing, and it works like a charm. I used my own created method and I noticed my most of the selenium scripts working fine without fail.

How below method works.
You need to pass three parameter
1- Driver- pass the driver reference, which will find the element.
2- Xpath – pass the xpath of the element, which you want to find of the page.
3- Time- pass the time it will keep polling after each second and if max limit exceeds then it will throw null pointer exception.

 

Above method will return you the WebElement then you can play with the element like do any operation based on your requirement.

Library to solve Synchronization in Selenium Webdriver

Synchronization in Selenium Webdriver

 

Now you can use above method in your test script.

Synchronization in Selenium Webdriver

 

Hope you will implement this method in your framework.

Kindly share your feedback on comment section.

 

 

18 Comments

  1. Harish
      • Harish
  2. Neeraj Kumar
  3. Preetish Kumar Mahato
  4. santhosh
  5. Ritesh kumar
  6. Premkumar
      • Gaurav Lad
  7. Ritesh kumar

Leave a Reply