Issue
I want to write a generic function that gets ExpectedConditions
and Locator
:
public WebElement findElementElements(ExpectedConditions expectedConditions, By locator){
WebDriver driver...
WebDriverWait webDriverWait...
return driver.webDriverWait().until(expectedConditions(locator));
}
But I get this compiler error: "Method call expected"
Solution
Not all ExpectedCondtions
return the same type… some return WebElement
, others return Boolean
. This method expects ExpectedConditions
that return WebElement
s.
public WebElement findElement(Function<WebDriver, WebElement> expectedCondition) {
return new WebDriverWait(driver, 10).until(expectedCondition);
}
and you can call it like
WebElement e = findElement(ExpectedConditions.elementToBeClickable(By.id("myId")));
NOTE: You don’t need the locator
parameter because that’s a required part of the ExpectedCondition
.
Answered By – JeffC
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0