簡體   English   中英

java.lang.NoSuchMethodError:org.openqa.selenium.support.ui.FluentWait.until(Lcom / google / common / base / Function;)Ljava / lang / Object;

[英]java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.FluentWait.until(Lcom/google/common/base/Function;)Ljava/lang/Object;

每當我在項目中嘗試使用wait.until(ExpectedConditions)時,都會遇到以下錯誤:

java.lang.NoSuchMethodError:org.openqa.selenium.support.ui.FluentWait.until(Lcom / google / common / base / Function;)Ljava / lang / Object;

我認為有問題的示例代碼:

public static void clickSearch(WebDriver driver,By by, int timeout){
    driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    WebDriverWait wait = new WebDriverWait(driver, 2);
    WebElement webElement = wait.until(ExpectedConditions.elementToBeClickable(by));
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    webElement.click();
}

FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(waitSeconds, TimeUnit.SECONDS).pollingEvery(5, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class);
wait.until(new ExpectedCondition<Boolean>() {
      @Override
      public Boolean apply(WebDriver driver) {
          return ((JavascriptExecutor) driver).executeScript("return document.readyState").toString().equals("complete");
      }
});

我有以下庫:

activation.jar
byte-buddy-1.8.3.jar
cglib-nodep-3.2.4.jar
commons-codec-1.10.jar
commons-collections4-4.1.jar
commons-exec-1.3.jar
commons-io-2.5-javadoc.jar
commons-io-2.5.jar
commons-lang3-3.5.jar
commons-logging-1.2.jar
dom4j-1.6.1.jar
dsn.jar
gson-2.8.5.jar
hamcrest-core-1.3.jar
hamcrest-library-1.3.jar
http-client-6.6.0.5.jar
httpclient-4.5.5.jar
httpcore-4.4.9.jar
httpmime-4.5.5.jar
imap.jar
jackson-annotations-2.9.1.jar
jackson-core-2.9.1.jar
jackson-databind-2.9.1.jar
java-client-3.3.0.jar
jaxen-1.1.6.jar
jcl-over-slf4j-1.7.21.jar
jcommander-1.72.jar
jna-4.4.0.jar
json-20151123.jar
jsr305-3.0.2.jar
junit-4.12.jar
jxl-2.6.12.jar
mail.jar
mailapi.jar
netty-3.5.7.Final.jar
ojdbc6.jar
okio-1.15.0.jar
pm-webdriver-6.6.0.5-javadoc.jar
pm-webdriver-6.6.0.5.jar
poi-3.17.jar
poi-examples-3.16.jar
poi-excelant-3.17.jar
poi-ooxml-3.17.jar
poi-ooxml-schemas-3.17.jar
poi-scratchpad-3.17.jar
selenium-3.13\selenium-api-3.13.0.jar
selenium-3.13\selenium-java-3.13.0.jar
selenium-3.13\selenium-remote-driver-3.13.0.jar
selenium-3.13\selenium-server-standalone-3.13.0.jar
selenium-3.13\selenium-support-3.13.0.jar
slf4j-api-1.7.25.jar
smtp.jar
testng-6.14.2.jar
xml-apis-2.9.1.jar
xmlbeans-2.6.0.jar
guava-26.0-jre.jar

我們不在我們的項目中使用Gradle / Maven。 我們將這些庫的物理副本存儲在某個位置,並使用它們通過ANT腳本構建可執行jar。 然后我們從命令行執行由ANT腳本創建的jar:

java.exe -cp <ProjectJarName>;<Location of jar libraries> <Main class name with whole package>.
For eg : java.exe project.jar;C:\Libraries\*.jar java.main.Main

當我搜索問題時,我看到的常見答案是添加了我嘗試過的最新的番石榴罐,但並沒有解決問題。 同樣在github的selenium論壇中,我看到人們通過更改pom.xml來解決問題,因為我不依賴於maven,因此可以更改我認為不必執行的順序。

該方法的方法簽名記錄在: https : //seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html#until-java.util.function。功能-

您正在傳遞此https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedCondition.html ,它擴展了com.google.common.base.Function

https://google.github.io/guava/releases/20.0/api/docs/com/google/common/base/Function.html

現在,此接口是舊版類型。 盡可能使用java.util.function.Function(或適當的原始專業化名稱,例如ToIntFunction)。 否則,至少可以通過使用lambda表達式或方法引用(而不是類)來減少對此類型的顯式依賴,從而使您的代碼將來更易於遷移。

要在需要其他類型功能的上下文中使用現有功能(例如,命名功能),請使用方法引用function :: apply。 com.google.common.base.Function的未來版本將擴展為java.util.function.Function,從而僅在一個方向上需要轉換代碼。 屆時,將正式禁止使用此界面。

這表明您的JRE版本或庫版本不匹配。 您收到的錯誤消息說,當Javadoc for until它的參數應該是java.util.function.Function時,您正在傳遞com.google.common.base.Function

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.Wait.until(Lcom/google/common/base/Function;) 使用 selenium-server-standalone-3.12.0 Google通訊錄-java.lang.NoSuchMethodError:com.google.common.collect.ImmutableSet.of([Ljava / lang / Object;)Lcom / google / common / collect / ImmutableSet; java.lang.NoSuchMethodError:帶有Selenium和Java的com.google.common.collect.ImmutableSet.of([Ljava / lang / Object;) Selenium Phantomjs 驅動程序 - java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String; Selenium 4: 獲取 java.lang.NoSuchMethodError: org.openqa.selenium.WebElement.getDomAttribute/String; 錯誤:: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V 線程“main”中的異常 java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;) java.lang.NoSuchMethodError: 'void org.openqa.selenium.support.PageFactory.initElements(org.openqa.selenium.SearchContext, java.lang.Object)' 線程“主”中的異常java.lang.NoSuchMethodError:org.openqa.selenium.io.FileHandler.unzip(Ljava / io / InputStream;)Ljava / io / File; java.lang.NoSuchMethodError: com.google.common.util.concurrent.SimpleTimeLimiter.create at org.openqa.Z8E00596AD8DE2213FF8F8D8478D5DriverService.remo
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM