java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.Wait.until(Lcom/google/common/base/Function;) using selenium-server-standalone-3.12.0

前端 未结 4 950
轮回少年
轮回少年 2021-01-19 07:38

I\'ve been struggling with selenium to fix this issue:

java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.Wait.until(Lcom/google/common/base/Function         


        
相关标签:
4条回答
  • 2021-01-19 08:07

    This error message...

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

    ...implies that the Guava version was incompatible.


    As you are using selenium-server-standalone-3.12.0 as per the contents of selenium-java-3.12.0 client kits the supported guava version is:

    guava-23.6-jre


    Snapshot

    guava


    Solution

    An immediate solution would be to:

    • Upgrade Guava with guava-23.6-jre.jar

    The real issue

    In your first update as you have confirmed that Guava version is 23.6-jre, the real issue seems to be constructor of FluentWait. The argument type for withTimeout and pollingEvery post Selenium v3.11.0, which was:

    • pollingEvery: pollingEvery(long duration, java.util.concurrent.TimeUnit unit)
    • withTimeout: withTimeout(long duration, java.util.concurrent.TimeUnit unit)

    Are now Deprecated and the new type is java.time.Duration. So your effective code block will be:

    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
    .withTimeout(Duration.ofSeconds(30))
    .pollingEvery(Duration.ofMillis(500))
    .ignoring(NoSuchElementException.class);
    

    You can find a detailed discussion in The type FluentWait is not generic; it cannot be parameterized with arguments error for FluentWait Class through Selenium and Java


    Additional Consideration

    Additionally,

    • Your JDK version is 1.8_71 which is pretty old and ancient.
    • Solution: Ensure that JDK is upgraded to current levels JDK 8u222.

    Best Practices

    As per the best practices you need to:

    • Upgrade JDK to recent levels JDK 8u222.
    • Upgrade Selenium to current levels Version 3.141.59.
    • GeckoDriver and Firefox specific:
      • Upgrade GeckoDriver to GeckoDriver v0.26.0 level.
      • GeckoDriver is present in the desired location.
      • GeckoDriver is having executable permission for non-root users.
      • Upgrade Firefox version to Firefox v72.0 levels.
    • ChromeDriver and Chrome specific:
      • ChromeDriver is updated to current ChromeDriver v79.0.3945.36 level.
      • Chrome is updated to current Chrome Version 79.0 level. (as per ChromeDriver v79.0 release notes)
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • (WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
    • (LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
    • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
    • Take a System Reboot.
    • Execute your Test as a non-root user.
    • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

    Reference

    You can find a relevant detailed discussion in:

    • org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList; with Selenium 3.5.3 Chrome 76
    0 讨论(0)
  • 2021-01-19 08:16

    Simple short answer: You have dependency issues with an outdated guava version!

    -> Do this: In every single project explicitly exclude the guava dependency from every single dependency that requests it (use the dependency graph to find these) or better exclude it in the parent (if you have one)

    -> Then add the guava 23.0 (or newer) dependency explicitly.

    This will fix it. Right now from somewhere an old guava version is being pulled that doesnt have the "until" method (or at least not with this parameter).

    Good Luck! :)

    0 讨论(0)
  • 2021-01-19 08:18

    This is compatibility issue. To solve it, you can use Guava version 21 + selenium version 3.2.0 + JDK 8.

    For more details you can check below link:

    https://softwaretestingboard.com/q2a/1907/function-webdriver-fluentwait-webdriver-applicable-arguments#axzz68BFzmEjv

    I hope it will help you.

    0 讨论(0)
  • 2021-01-19 08:21

    I think you should check under D:\sln\ and D:\sln\lib\ if there's any other version of selenium library in there. Delete it out if there's one.

    From the error message, it seems like when you execute the batch script it use a different version of Selenium from a different selenium jar file. Probably the old version of selenium jar that haven't had the Wait.until method yet.

    0 讨论(0)
提交回复
热议问题