How can I get the Findby
type and string from a WebElement
?
I am using a self-built webDriverWait
function that will be able to receive By Or Webelement to be used at the presenceOfElementLocated() function.
Defining the WebElement
@FindBy(xpath = "//div[@id='calendar-1234']")
private WebElement calander;
The Two webDriverWaitFor Functions
The first uses By and is working okay: , and the second uses webElement
public void webDriverWaitFor(WebDriver driver, By by) throws ElementLocatorException {
try{
(new WebDriverWait(driver, 5))
.until(ExpectedConditions.presenceOfElementLocated( by ));
}
catch (Exception e) {
throw new ElementLocatorException(by);
}
}
The second uses WebElement and I am trying to get the By type and string. this implimintation is not good: By.id(webElement.getAttribute("id"))
public void webDriverWaitFor(WebDriver driver, WebElement webElement) throws ElementLocatorException {
try{
(new WebDriverWait(driver, 5))
.until(ExpectedConditions.presenceOfElementLocated( By.id(webElement.getAttribute("id")) ));
}
catch (Exception e) {
throw new ElementLocatorException( By.id(webElement.getAttribute("id")) );
}
}
how will I be able to implement the following?
webDriverWaitFor(driver, calander);