【发布时间】:2020-01-17 17:20:47
【问题描述】:
我在使用 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
构建.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;
}
【问题讨论】:
-
假设您正在尝试编译某种工作开源,我的猜测是:您的 Java 版本是错误的。您应该使用 1.8 但使用 1.7 ;反之亦然。
-
运气不好。在我使用 java 1.8 之前。现在切换到 1.7 并遇到了许多问题。
-
你的 GOTO_ICON 定位器是什么?
-
我不确定我是否遵循,在某些时候这段代码可以正常工作,但现在不行了吗?根据您提供的代码,我猜您正在尝试直接从 webdriver 调用 .until(),但是您应该将 webdriver 作为参数传递给 fluentwait 构造函数。
-
@kushalツ GOTO_ICON = By.id("GoTo");
标签: java selenium-webdriver gradle ui-automation