Quality Testing

Quality is delighting customers

Best way to Implement WebElement isExist Method for WebDriver

Make the class file with name on the WebDriver you are using.

like here i am using FirefoxDriver so have created 1 java class file as FirefoxDriver.java

and added code as below

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class FirefoxDriver extends org.openqa.selenium.firefox.FirefoxDriver.FirefoxDriver

{
public FirefoxDriver(WebDriver driver) {
super(driver);
// TODO Auto-generated constructor stub
}

public boolean exist(By by)
{
try
{
this.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
this.findElement(by);
return(true);
}
catch (Exception e) {
// TODO: handle exception
return(false);
}
}

}

 

 

 

now when you initialise your driver object with this class it will have additional method like exist... which will return true if specified web element is present on page or not......

Views: 253

Reply to This

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2019   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service