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 in Selenium by Sushmita
28 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 by Anvi
• 11,690 points

Related Questions In Selenium

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,350 points
140 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 in Selenium by Subhash
117 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 in Selenium by Vaishali Walia
73 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,050 points
413 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,130 points
772 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,130 points
408 views
0 votes
1 answer
0 votes
1 answer