Reputation: 427
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"
Upvotes: 0
Views: 123
Reputation: 25542
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
.
Upvotes: 1