我正在尝试为 selenium webdriver 等待实现 Java Lambda 概念。我需要转换自定义 webdriver 等等
(new WebDriverWait(driver(), 5))
.until(new ExpectedCondition<WebElement>() {
public WebElement apply(WebDriver d) {
return d.findElement(By.linkText(""));
}
});
到
(new WebDriverWait(driver(), 5)).until((driver) -> driver.findElement(By.linkText("")));
但它不匹配'until'引用的功能接口(interface)并抛出错误。
所以我尝试通过它支持的 Lambda。
尝试1
Predicate<WebDriver> isVisible = (dr) -> dr.findElement(
By.linkText("")).isDisplayed();
webDriverWait.until(isVisible);
它有点用,但不是我所需要的,因为它只返回 void。
需要您的帮助或建议。
最佳答案
问题出在你的语法上。下面的代码对我来说非常有用
WebElement wer = new WebDriverWait(driver, 5).until((WebDriver dr1) -> dr1.findElement(By.id("q")));
你的代码问题
//What is this driver() is this a function that returns the driver or what
//You have to defined the return type of driver variable in until() function
//And you cant use the same variable names in both new WebdriverWait() and until() see my syntax
(new WebDriverWait(driver(), 5)).until((driver) -> driver.findElement(By.linkText("")));
关于java - 显式等待的 Selenium Java Lambda 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31102351/