How can i get the xpath from a WebElement
Webelement element= driver.findElement(By.xpath("//div//input[@name='q']"));
something like
element.getLocator(); ->> this should be like this "//div//input[@name='q']"
how to do the same? I have created below method and passed xpath as parameter. I want to create same method and pass webElement as parameter:
public boolean isElementPresentAndVisible(String xpath){
if(driver.findElements(By.xpath(xpath)).size()!=0){
if(driver.findElement(By.xpath(xpath)).isDisplayed()){
System.out.println(xpath+" present and Visible");
return true;
}else{
System.err.println(xpath+" present but NOT Visible");
return false;
}
}else{
System.err.println(xpath+" NOT present");
return false;
}
}