我有一个运行完美的自动化脚本。 但是当我将脚本复制给同事时,以下代码行无法编译并给出以下错误。
wait.until(ExpectedConditions.textToBePresentInElement(oq.findElement("_ctl0_ContentPlaceHolder1_industryQB_selectedIndustryLabel"), "F461300 Computer Wholesaling"));
以下错误
Error:(231, 13) java: no suitable method found for until(org.openqa.selenium.support.ui.ExpectedCondition<org.openqa.selenium.WebElement>)
method org.openqa.selenium.support.ui.FluentWait.until(com.google.common.base.Predicate<org.openqa.selenium.WebDriver>) is not applicable
(argument mismatch; org.openqa.selenium.support.ui.ExpectedCondition<org.openqa.selenium.WebElement> cannot be converted to com.google.common.base.Predicate<org.openqa.selenium.WebDriver>)
method org.openqa.selenium.support.ui.FluentWait.<V>until(com.google.common.base.Function<? super org.openqa.selenium.WebDriver,V>) is not applicable
(cannot infer type-variable(s) V
(argument mismatch; org.openqa.selenium.support.ui.ExpectedCondition<org.openqa.selenium.WebElement> cannot be converted to com.google.common.base.Function<? super org.openqa.selenium.WebDriver,V>))
这是我所做的步骤。 安装IDE(intellj Idea),将jdk添加到项目中,将selenium jar添加到项目中。 复制并粘贴 Java 文件。
我什至尝试过复制整个项目,除了这个之外,每一种方法都得到了解决。
该脚本在我的机器上仍然可以完美运行。但在新机器上不行。
如果有任何不清楚的地方,请随时问我。
我现在没有主意了。
最佳答案
根据documentation <强> textToBePresentInElement
已弃用。您可能使用尚未弃用的旧版本,而您的同事使用最新版本的 Selenium
使用textToBePresentInElementLocated(By, String)
相反
编辑 而且,我不知道如何
wait.until(ExpectedConditions.textToBePresentInElement(oq.findElement("_ctl0_ContentPlaceHolder1_industryQB_selectedIndustryLabel"), "F461300 Computer Wholesaling"));
将编译。参数
ExpectedConditions.textToBePresentInElement(By , String)
预期为 By
, String
。您正在尝试通过WebElement
而不是By
选择器。此外,findElement()
不接受String
但某种By
选择器对我来说似乎也是错误的。
正确实现:public static ExpectedCondition<java.lang.Boolean> textToBePresentInElement(By locator, java.lang.String text)
关于java - 代码无法编译不同的 PC Selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29000363/