How to create Custom wait library for handling synchronization in Selenium Webdriver

0 votes
How to create Custom wait library for handling synchronization in Selenium Webdriver?
Jul 23, 2019 in Selenium by Sushmita
2,011 views

1 answer to this question.

0 votes

Hi Sushmita, to solve Synchronization issue in Selenium Webdriver, you can create Custom Wait library in the following manner:

public class Utility
{

public static WebElement isElementPresnt(WebDriver driver,String xpath,int time)
{

WebElement element = null;
for(int i=0;i<time;i++)
{
try{
element=driver.findElement(By.xpath(xpath));
break;
}
catch(Exception e)
{
try
{
Thread.sleep(1000);
} catch (InterruptedException e1)
{
System.out.println("Waiting for element to appear on DOM");
}
}
}
return element;
}
}

Now you can use above method in your test scripts:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

import Library.Utility;

public class SearchBus
{

@Test
public void checkBuses()
{
WebDriver driver=new FirefoxDriver();

driver.manage().window().maximize();

driver.get("https://www.edureka.co/");

Utility.isElementPresnt(driver,".//*[@id='txtSource']", 20).sendKeys("Bangalore");

Utility.isElementPresnt(driver,".//*[@id='txtDestination']", 20).sendKeys("Chennai");
}
}
answered Jul 23, 2019 by Anvi
• 14,150 points

Related Questions In Selenium

0 votes
2 answers
0 votes
1 answer

How to wait for the webpage to load in selenium using java

Firstly, when you launch a web application, ...READ MORE

answered Aug 29, 2018 in Selenium by bug_seeker
• 15,510 points
1,955 views
0 votes
1 answer

How to do session handling in Selenium Webdriver?

Hey Lalita, you can perform following steps ...READ MORE

answered Jun 20, 2019 in Selenium by Subhash
11,425 views
0 votes
1 answer

How to apply wait for new window using Selenium WebDriver?

As sometimes during web automation, when you ...READ MORE

answered Jul 10, 2019 in Selenium by Vaishali Walia
9,217 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,771 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,187 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,263 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,901 views
0 votes
1 answer

How to add Junit library in Eclipse to use with Selenium Webdriver?

Hi Jacky, to add JUnit library in ...READ MORE

answered Jun 12, 2019 in Selenium by Anvi
• 14,150 points
6,605 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP