selenium: FluentWait changes WebDriverWait().until(ExpectedCondition...) fails with java.lang.NoSuchMethodError

Meta

OS: Windows 7 Selenium Version: 3.2.0 Browser: Chrome (problem is not related to browser) Browser Version: 56.0.2924.87 (64-bit) Java: jdk 1.8 (latest)

Problem

I had the following setup: OS: Windows 7 Selenium Version: 3.0.1 Browser: Chrome (problem is not related to browser) Browser Version: 56.0.2924.87 (64-bit) Java: jdk 1.8 (latest)

I was using guava - 18.0 version and had a tests which were running fine.

Then I decided to upgrade the whole selenium grid environment to use 3.2.0 webdriver. I went through the changes and updated the pom.xml file to use 3.2.0 selenium-java and guava 21.0. Then I ran the same tests and all of them failed in the following code fragment:

public void waitForElementToLoad(By locator, long timeOutInSeconds) {
        new WebDriverWait(webDriver, timeOutInSeconds).until(ExpectedConditions.visibilityOfElementLocated(locator));
    }

with the following reason:

 java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.WebDriverWait.until(Ljava/util/function/Function;)Ljava/lang/Object;

Expected Behavior

If the error above is expected please add some suggestions how to use WebDriverWait + ExpectedConditions

Actual Behavior

The tests are failing because of the changes done related to FluentWait. Same piece of code works fine with 3.0.1 and guava 18.0.

Steps to reproduce

    @Test
    public void example() throws Throwable {
        webDriver.get("https://www.google.com/");
        new WebDriverWait(webDriver, 30000).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[name='q']")));
    }

Thank you in advance!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 34 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Hi all, to @MichaelCowanPdx If you use maven - execute ‘mvn dependency:tree -Dverbose’ - verbose flag display conflicting dependencies Make search by results of dependency tree and find “guava” - if there few libs “guava” in different dependencies with conflicts - make exclude for older versions of guava in another dependencies and leave v.21.0 (included to selenium-java beginning from v3.2.0) This problem may be related to so called Maven “nearest-wins” strategy during resolving version conflicts of transitive dependencies. Best way - use maven “dependencyManagemenet”

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>21.0</version>
      </dependency>
   </dependencies>
</dependencyManagement>

In this way maven always resolve conflict with version from dependencyManagement

Here is my workaround:

  1. Open new jar, like 3.5.0, with zip. Delete following classes under \org\openqa\selenium\support\ui: FluentWait.class Wait.class WebDriverWait.class
  2. Open jar 3.0.4 or below with zip. Move following classes under \org\openqa\selenium\support\ui: FluentWait$1.class FluentWait$2.class FluentWait$3.class FluentWait.class Wait.class WebDriverWait.class to the new jar. Not perfect, but it worked to me.

Have the same problem. Got the same error when running via testng.xml. Also cannot run via Eclipse, got the same error as well.

My settings: OS: Win 7 Guava 21.0 Selenium Version: 3.1.0 or later Browser: Chrome (problem is not related to browser) Java: jdk 1.8 (latest) Eclipse: Kepler

Even I have faced the same issue adding guva and selenium-support dependencies resolved my issue. <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>21.0</version> </dependency>

<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-support</artifactId> <version>3.2.0</version> </dependency>

if you are still facing the issue then update selenium standalone server to the selenium version that you are using. there is no maven dependency for selenium standalone server so you have to download the required version and add it to build path.

Note : After adding all above dependencies, delete selenium folder from .m2 folder and build it.

All the best.

I am also facing this issue. I dont quite understand why this issue was closed when it is clearly a common occurrence.

Can someone from the Selenium team please re-open this issue?

Have the same problem. Got the same error when running via testng.xml. Also cannot run via Eclipse - Neon got the same error as well.

My settings: OS: Win 7 Guava 22.0 Selenium Version: 3.4 Browser: Chrome (problem is not related to browser) Java: jdk 1.8 (latest) Eclipse: Neon

I tried different configurations. First try. new WebDriverWait(this, MAX_TIMEOUT_SECONDS).until(ExpectedConditions.visibilityOf(webElement));

Second try from searching google. Wait<WebDriver> wait = new FluentWait<WebDriver>(this) .withTimeout(MAX_TIMEOUT_SECONDS, SECONDS) .pollingEvery(5, SECONDS) .ignoring(NoSuchElementException.class); wait.until(ExpectedConditions.visibilityOf(webElement));

Third try from searching google. Wait<WebDriver> wait = new FluentWait<WebDriver>(this) .withTimeout(MAX_TIMEOUT_SECONDS, SECONDS) .pollingEvery(5, SECONDS) .ignoring(NoSuchElementException.class); wait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id(“table”)); } }); They all fail.

Anyone solve this issue with testNG?

Yes, I am also getting the same issue with guava version as Latest, My issue get resolved when I mentioned the guava version as 21 in dependency.