使用java和gradle版本3.4编译selenium自动化应用程序时出现以下错误。
错误:
method until in class FluentWait<T> cannot be applied to given types;
return getWebDriverWait().until(ExpectedConditions.elementToBeClickable(GOTO_ICON));
^
required: Function<? super WebDriver,V>
found: ExpectedCondition<WebElement>
reason: cannot infer type-variable(s) V
(argument mismatch; ExpectedCondition<WebElement> cannot be converted to Function<? super WebDriver,V>)
where V,T are type-variables:
V extends Object declared in method <V>until(Function<? super T,V>)
T extends Object declared in class FluentWait
的build.gradle
compile 'io.appium:java-client:3.1.0'
compile 'com.applitools:eyes-selenium-java-jersey1x:2.29'
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.46.0'
compile 'org.seleniumhq.selenium:selenium-firefox-driver:2.52.0'
compile 'org.seleniumhq.selenium:selenium-ie-driver:2.52.0'
源代码:
By GOTO_ICON = By.id("GoTo");
String windowContentLoaded = "//*[@id=\"windowContentLoaded\"]";
public WebElement getGoToHeader() {
waitForPageToBeLoaded();
return getWebDriverWait().until(ExpectedConditions.elementToBeClickable(GOTO_ICON));
}
public void waitForPageToBeLoaded() {
sleepSeconds(3);
getWebDriverEx().waitForInvisibleElement(By.xpath(windowContentLoaded));
return;
}
答案 0 :(得分:2)
不确定 Selenium 2.46.0 中错误的原因是什么,但是从版本 3.x 切换到版本时,我遇到的错误完全相同 4.x 。
这可能无法帮助OP解决问题,但是我为在搜索相同异常的情况下来到这里的人们发布了一个解决方案。
在最新版本的Selenium框架中,getWebDriverWait().until()
接口有所变化:
现在,它接受带有一个参数(WebDriver
)的函数接口,并根据WebDriverWait
的实现返回值,该实现在大多数情况下为ExpectedConditions
。
尝试将您的代码更改为:
public WebElement getGoToHeader() {
waitForPageToBeLoaded();
return getWebDriverWait().until(
webDriver -> ExpectedConditions.elementToBeClickable(GOTO_ICON).apply(webDriver)
);
}