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 22, 2019 in Selenium by Sushmita
90 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.redbus.in/");

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

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

Related Questions In Selenium

0 votes
1 answer
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 28, 2018 in Selenium by bug_seeker
• 15,390 points
301 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
1,567 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 9, 2019 in Selenium by Vaishali Walia
652 views
0 votes
1 answer

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,510 points
1,553 views
0 votes
1 answer
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,870 points
1,491 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,870 points
1,271 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 11, 2019 in Selenium by Anvi
• 14,010 points
78 views
0 votes
1 answer