'What causes java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Require when using WebDriverManager 5.0.3

I have a spring boot application, that I want to test with Selenium. I'm using WebDriverManager v5.0.3

When settin up the WebDriver WebDriverManager.chromedriver().setup(); I get an exception:

java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Require

or

java.lang.ClassNotFoundException: org.openqa.selenium.internal.FindsById

My pom.xml contains this:

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>4.1.0</version>
        </dependency>


Solution 1:[1]

There is an incompatibility between WebDriverManager v5.0.3 and Selenium v4. After Downgrading Selenium to the latest v3 subversion, everything works.

Update: As of the comment below it works with WebDriverManager >=v5.1.0

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>3.141.59</version>
        </dependency>

Solution 2:[2]

You can check your libraries with your project.

I face this problem too, finally I found in my maven project the dependencies libraries of selenium doesn't have same version.

I create a new project use Gradle other than Maven with selenium 4.0.0 and it works fine.

so I check the incorrect libraries and manually adjust to same version with selenium-java library in my pom.xml. finally it works.

BTW: mvn clean install doesn't work for me.

    <!-- only this origin -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.0.0</version>
    </dependency>
    <!-- add belows for these dependencies version is not 4.0.0 when automatically generated -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>4.0.0</version>
    </dependency>

Solution 3:[3]

You need to execute mvn clean compile command on the same directory where the pom.xml file is after you change version to 4** or adding this dependency to pom file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 richardstone
Solution 3 Peter Csala