Ina*_*ble 2 java ui-automation gradle selenium-webdriver
使用 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
Run Code Online (Sandbox Code Playgroud)
构建.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'
Run Code Online (Sandbox Code Playgroud)
源代码:
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;
}
Run Code Online (Sandbox Code Playgroud)
不确定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)
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3780 次 |
| 最近记录: |