java - 代码无法编译不同的 PC Selenium

标签 java selenium selenium-webdriver

我有一个运行完美的自动化脚本。 但是当我将脚本复制给同事时,以下代码行无法编译并给出以下错误。

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/

相关文章:

java - Struts2:获取用户来自的Url

java - JComponent 显示完整尺寸或根本不显示

java - Selenium webdriver 线程 sleep 未按预期工作

java 可执行 jar 文件无法在另一台计算机上运行

javascript - Protractor 在忽略同步期间等待,浏览器 implicitTimeout 与 browser.wait 超时

python - 我的脚本无法解析复杂网页中的项目

java - Log4J2 配置中的主要参数

java - 如果在围绕同步锁的循环中使用变量,是否会读取 "fresh from main memory"?

javascript - Selenium - 元素在点上不可点击

javascript - 任何 Python 替代 Selenium 以编程方式登录需要 JavaScript 登录的网站?