我在Selenium WebDriver中编译代码时遇到了这个错误:
@BeforeClass setUp java.lang.Error:未解决的编译问题: Wait类型中的(Function)方法不适用于 arguments(new Function(){})函数无法解析为类型
我的代码是:
Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement myLoginButton = wait.until(
new Function() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("btnLogin"));
}
}
)
答案 0 :(得分:0)
为了创建自己的功能,您应该提供Function<? super WebDriver, ?>
功能。
或者,创建新对象ExpectedCondtions
示例:
Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement myLoginButton = wait.until(
new ExpectedCondition<WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("btnLogin"));
}
}
)
答案 1 :(得分:0)
论点中存在一些小问题&amp;您用于 FluentWait
的语法。这是您的工作代码块:
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
//your code
Wait<WebDriver> wait = new FluentWait(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
WebElement myLoginButton = wait.until(new Function<WebDriver, WebElement>()
{
public WebElement apply(WebDriver driver)
{
return driver.findElement(By.id("btnLogin"));
}
});