Search code examples
javaselenium-webdriverclasspathnosuchmethoderror

java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.WebDriverWait.until


Happens error after autotests java.lang.NoSuchMethodError:

org.openqa.selenium.support.ui.WebDriverWait.until(Lcom/google/common/base/Function;)Ljava/lang/Object;

Environment:

  • selenium-java-3
  • guava-25.0-jre
  • java 8
  • Google Chrome 77 version
  • ChromeDriver 77.0.3865.40

Code:

WebDriverWait alertAwaiter = new WebDriverWait(webDriver, 2);
alertAwaiter.until(ExpectedConditions.alertIsPresent());

When the second line of this code is executed, java.lang.NoSuchMethodError occurs:

org.openqa.selenium.support.ui.WebDriverWait.until(Lcom/google/common/base/Function;)Ljava/lang/Object;

It is not possible to change this code, is it possible to do something using other versions of drivers or in some other way?


Solution

  • You need to find a proper version of selenium library and put it to the classpath. The modern versions use java.util.Function instead of com.google.common.base.Function, see https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html#until-java.util.function.Function-

    So you need to you quite old version of the Selenium driver in the application classpath if you can't modify the source code.

    Try to downgrade to selenium 3.0.1 or 2.x. The latest 2.53.1 version uses guava, and version 3.0.1 seems to be the last one with guava usage.