Vis*_*ady 7 java lambda selenium-webdriver
我正在尝试为selenium webdriver等实现Java Lambda概念.我需要转换自定义webdriver等待这样的事情
(new WebDriverWait(driver(), 5))
.until(new ExpectedCondition<WebElement>() {
public WebElement apply(WebDriver d) {
return d.findElement(By.linkText(""));
}
});
Run Code Online (Sandbox Code Playgroud)
至
(new WebDriverWait(driver(), 5)).until((driver) -> driver.findElement(By.linkText("")));
Run Code Online (Sandbox Code Playgroud)
但它与'until'引用的函数接口不匹配并抛出错误.
所以我尝试传递Lambda,因为它支持.
Attempt1
Predicate<WebDriver> isVisible = (dr) -> dr.findElement(
By.linkText("")).isDisplayed();
webDriverWait.until(isVisible);
Run Code Online (Sandbox Code Playgroud)
它有点工作,但不是我需要的,因为它只返回空白.
需要你的帮助或建议.
问题在于你的语法.下面对我来说非常合适
WebElement wer = new WebDriverWait(driver, 5).until((WebDriver dr1) -> dr1.findElement(By.id("q")));
Run Code Online (Sandbox Code Playgroud)
你的代码问题
//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("")));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4635 次 |
| 最近记录: |