显式等待的Selenium Java Lambda实现
我正在尝试为SeleniumWebDriver实现JavaLambda概念。我需要转换自定义webdriver等类似的东西显式等待的Selenium Java Lambda实现,java,selenium-webdriver,lambda,Java,Selenium Webdriver,Lambda,我正在尝试为SeleniumWebDriver实现JavaLambda概念。我需要转换自定义webdriver等类似的东西 (new WebDriverWait(driver(), 5)) .until(new ExpectedCondition<WebElement>() { public WebElement apply(WebDriver d) { return d.findEl
(new WebDriverWait(driver(), 5))
.until(new ExpectedCondition<WebElement>() {
public WebElement apply(WebDriver d) {
return d.findElement(By.linkText(""));
}
});
但它与'until'的函数接口不匹配,它引用并抛出错误
所以我试着通过Lambda,因为它支持
尝试1
Predicate<WebDriver> isVisible = (dr) -> dr.findElement(
By.linkText("")).isDisplayed();
webDriverWait.until(isVisible);
谓词isVisible=(dr)->dr.findElement(
By.linkText(“”).isDisplayed();
webDriverWait.until(可见);
它有点工作,但不是我所需要的,因为它只返回空
需要您的帮助或建议。问题在于您的语法。以下内容对我来说非常有用
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("")));
因为方法
WebDriverWait#until
重载:并且,编译器无法推断lambda方法的参数类型
在本例中,两个函数接口
Function
和Predicate
都使用一个参数,在本例中,它要么是确切的错误是什么?下面是我得到的错误“类型不匹配:无法从WebElement转换为boolean”按照您的建议为Lambda表达式添加了类型声明,并按预期工作。问题:该类型不是自动推断出来的吗?然后接受它作为答案,因为它将有助于其他引用
//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("")));