15

I am new to selenium tests and I am currently watching some youtube videos using maven.

Today I tried a few codes and worked fine but when accessing one store page and trying to search a product it gives me "Access Denied" message So I tried a few ways to open chrome instead of chromedriver.

But I gave up and was willing to try another webpage. But now chromedriver wont open (gives error message). operadriver, geckodriver and etc will immediately close after launch.

I am getting this error:

java.lang.NoSuchMethodError: 'com.google.common.collect.ImmutableMap com.google.common.collect.ImmutableMap.of(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)'

I tried looking in a lot of places but most said it was guava version, I dont use guava, even though I tried adding it to dependencies...

My code is this:

public class TestYoutubeClass {
    WebDriver driver;
    @Before
    public void runDriver(){
        WebDriver driver = new ChromeDriver();
        driver.get("http://www.kabum.com.br");

I tried starting from the beginning and nothing worked. I am using IntelliJ On pom.xml I added: junit; selenium-java and webdrivermanager.

Every help is really appreciated.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Tuna
  • 151
  • 1
  • 1
  • 4

12 Answers12

15

The issue comes from conflicting Guava (transitive dependency) versions.

It should be fixed with the WebDriverManager version 5.1.0.

As an alternative, you can also use the <dependencyManagement> section of your pom.xml to force a resolution of the latest Guava version:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>31.0.1-jre</version>
    </dependency>
  </dependencies>
</dependencyManagement>

or exclude the Guava dependency from the WebDriverManager (no longer required for >= 5.1.0):

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.0.3</version>
    <exclusions>
        <exclusion>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </exclusion>
    </exclusions>
</dependency>

PS: To ensure dependency convergence for your Maven project, consider adding the Maven Enforcer Plugin to detect multiple versions of the transitive dependency early on.

rieckpil
  • 10,470
  • 3
  • 32
  • 56
  • Only adding to the section solved the issue for me – Teo J. Jul 29 '22 at 08:37
  • I used the second method you posted, adding the block to the same pom.xml that contains the org.selenium.hq dependencies. Rebuilt and did a clean maven install. No change. Still fails with java.lang.NoSuchMethodError: 'com.google.common.collect.ImmutableMap – Frank H. Dec 13 '22 at 12:44
  • I suggest adding `test` to the dependency. – not2savvy Apr 27 '23 at 11:30
12

I'm using maven and downgraded Version 4.1.2 to 4.1.1 solved my problem

<dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.1.1</version>
</dependency>
Alex Boghda
  • 121
  • 2
7

I also faced the above issue after adding below dependency it worked fine. I am using Chrome 98 version

<dependencies>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>31.0.1-jre</version>
    </dependency>
  </dependencies>
Upasana
  • 71
  • 1
2

Just add

    workbook.close();

Or try this code in your pom.xml, it works for me

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>31.0.1-jre</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.2.0</version>
    </dependency>

    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>5.0.1</version>
    </dependency>
2

Looking at the master branch of Guava today, it looks like the actual issue is simply that no version of com.google.common.collect.ImmutableMap.of(...) accepts more than 10 parameters (the thread starter's error shows 12). It is documented in the source code here:

https://github.com/google/guava/blob/master/guava/src/com/google/common/collect/ImmutableMap.java

This is the comment after the version that accepts 10 entries: // looking for of() with > 10 entries? Use the builder or ofEntries instead.

I am suggesting the usage of .of() in Selenium is changed to on of the suggested methods in the copied comment above since this seems to be a recurring issue for a lot of people.

Will try to re-open this issue to get this taken care of: https://github.com/SeleniumHQ/selenium/issues/10324

PVDM
  • 98
  • 7
1

This error message...

java.lang.NoSuchMethodError: 'com.google.common.collect.ImmutableMap com.google.common.collect.ImmutableMap.of(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)'

...implies that there is NoSuchMethod as com.google.common.collect.ImmutableMap which indicates it might be corrupted or there is some incompatibility between the version of the binaries you are using specifically with the guava version / dependency (maven).


You need to take care of a couple of things as follows:

  • You need to add the System.setProperty():

    System.setProperty("webdriver.gecko.driver","C:\\Program Files\\Java\\jre1.8.0_231\\lib\\ext\\geckodriver.exe");
    
  • Use only a single instance of WebDriver, either from the class scope or from the method scope.

  • Effectively, you line of code will be;

    public class TestYoutubeClass {
        WebDriver driver;
        @Before
        public void runDriver(){
            System.setProperty("webdriver.chrome.driver","/path/to/chromedriver");
            driver = new ChromeDriver();
            driver.get("http://www.kabum.com.br");
    
  • Incase you are using deleting the corrupt/incompatible .m2 folder can solve your issue.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

Theres seems to be a bug in 5.0.x versions of webdrivermanager, see last two messages in this thread - https://github.com/bonigarcia/webdrivermanager/issues/576

Try switching the webdrivermanager dependency version to 4.4.3, worked for me.

Alex.K
  • 234
  • 4
  • 12
  • there's been an update to webdrivermanager, looks like this issue is fixed in version 5.1.0 now. – Alex.K Feb 20 '22 at 06:11
1

If you are using Maven pom.xml file then check the version of the WebDriverManager below 5.1.0 . I used the below version

(5.1.0)

to solve the shown issue!

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.1.0</version>
</dependency>
Asraful Haque
  • 1,109
  • 7
  • 17
1

use version version 4.1.1

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.1.1</version>
    </dependency>
siva
  • 11
  • 1
1
<dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>31.0.1-jre</version>
    </dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager  -->
<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.1.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.2.0</version>
</dependency>
I used above version in pom.xml.This will help me to come out of this error.
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 05 '23 at 15:34
0

I have personally solved these with these versions:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <spring.boot.version>1.5.21.RELEASE</spring.boot.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.1.1</version>
    </dependency>

    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>5.0.1</version>
    </dependency>

</dependencies>
  • What solved it? You're posting a bunch of versions, but not a solution? – Frank H. Dec 13 '22 at 12:31
  • To solved this error (java.lang.NoSuchMethodError: 'com.google.common.collect.ImmutableMap error when trying to execute tests using Chromedriver and Maven) I have change the versions of my dependencies. With these versions I no longer have the above error – Enzo33B3I1I2 Dec 28 '22 at 11:24
0

Spend another 3 hours fighting with selenium.

That worked for me:

    <selenium.version>4.1.2</selenium.version>
    <selenium-webdrivermanager.version>5.0.1</selenium-webdrivermanager.version>
    <guava.version>31.0.1-jre</guava.version>


    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-leg-rc</artifactId>
        <version>${selenium.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>${selenium.version}</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>${selenium.version}</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>${selenium.version}</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>${selenium.version}</version>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>${selenium-webdrivermanager.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>${guava.version}</version>
    </dependency>
Dmitri Algazin
  • 3,332
  • 27
  • 30