代码不编译不同的 PC Selenium
Code not Compiling different PC Selenium
我有一个运行完美的自动化脚本。
但是当我将脚本复制给我的同事时,以下代码行无法编译并出现以下错误。
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)
我有一个运行完美的自动化脚本。 但是当我将脚本复制给我的同事时,以下代码行无法编译并出现以下错误。
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)