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

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,向项目添加了硒罐。
复制并粘贴Java文件。

我什至尝试将整个项目复制过来,除此方法外,每种方法均得到解决。

该脚本在我的机器上仍然可以正常运行。但是不在新机器上。

如果不清楚,请随时问我任何问题。

我现在没主意了。

最佳答案

根据documentationtextToBePresentInElement被弃用。您可能使用的是不建议使用的旧版本,而您的同事使用的是最新版本的Selenium

使用textToBePresentInElementLocated(By, String)代替

编辑
而且,我不确定

wait.until(ExpectedConditions.textToBePresentInElement(oq.findElement("_ctl0_ContentPlaceHolder1_industryQB_selectedIndustryLabel"), "F461300 Computer Wholesaling"));


将编译。参数

ExpectedConditions.textToBePresentInElement(By , String)


期望是ByString。您试图传递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/

10-12 01:24
查看更多