Java 类型函数不是泛型函数;无法使用参数对其进行参数化<;WebDriver、WebElement>; Wait Wait=new FluentWait(驱动程序) .withTimeout(持续时间秒(30)) .pollingEvery(持续时间:百万(500)) .忽略(NoSuchElementException.class); WebElement foo=wait.until(新函数(){ 公共WebElement应用(WebDriver){ 返回驱动程序findElement(按名称(“q”); } });
尝试使用Selenium 3.141.59处理Fluent wait实现,但出现指定的编译时错误。我主要关注“新函数方法” 我不相信这是复制品。这个问题听起来可能是一样的,但没有一个解决方案对我有效 错误显示:Java 类型函数不是泛型函数;无法使用参数对其进行参数化<;WebDriver、WebElement>; Wait Wait=new FluentWait(驱动程序) .withTimeout(持续时间秒(30)) .pollingEvery(持续时间:百万(500)) .忽略(NoSuchElementException.class); WebElement foo=wait.until(新函数(){ 公共WebElement应用(WebDriver){ 返回驱动程序findElement(按名称(“q”); } });,java,selenium-webdriver,fluentwait,Java,Selenium Webdriver,Fluentwait,尝试使用Selenium 3.141.59处理Fluent wait实现,但出现指定的编译时错误。我主要关注“新函数方法” 我不相信这是复制品。这个问题听起来可能是一样的,但没有一个解决方案对我有效 错误显示: Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(Duration.ofSeconds(30)) .pollingEvery(Duration.ofMill
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofMillis(500))
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.name("q"));
}
});
类型函数不是泛型函数;不能使用参数对其进行参数化
对于这种显式等待,您实际上想做什么
您可以使用预定义的预期条件:
The type Function is not generic; it cannot be parameterized with arguments <WebDriver, WebElement>
出现问题的原因是您试图创建一个函数的新实例,而该函数是一个接口,您不能这样做。您可以将上述ExpectedCondition重构为:
wait.until(ExpectedConditions.presenceOfElementLocated(By.name("q")));
等待.until(新的ExpectedCondition(){
@凌驾
公共WebElement应用(WebDriver){
返回驱动程序findElement(按名称(“q”);
}
});
它看起来与您的尝试非常接近,但不太可读或可重用。我建议您使用自己的期望条件创建自己的帮助器类,这些条件与标准类似。可能您没有导入正确的函数接口(或者另一个同名的接口/类正在隐藏它)。
wait.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
return driver.findElement(By.name("q"));
}
});