Home > OS >  What causes java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Require when using WebDrive
What causes java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Require when using WebDrive

Time:12-02

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>

CodePudding user response:

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

        <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>

CodePudding user response:

I just ran into this very same problem. Peeking into the pom.xml of WebDriverManager, I can see that the selenium-java is 4.1.0 with provided scope. My situation occurs when I attempt to construct the driver ....

ChromeOptions capabilities = (ChromeOptions) createCapabilities(); ChromeDriverService chromeDriverService =ChromeDriverService.createDefaultService(); ChromeDriver webDriver = new ChromeDriver(chromeDriverService, capabilities);

and that is when I see the stack trace:

Starting ChromeDriver 96.0.4664.45 (76e4c1bb2ab4671b8beba3444e61c0f17584b2fc-refs/branch-heads/4664@{#947}) on port 17826
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

Step failed
java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Require
    at org.openqa.selenium.json.NumberCoercer.<init>(NumberCoercer.java:49)
    at org.openqa.selenium.json.JsonTypeCoercer.<init>(JsonTypeCoercer.java:71)
    at org.openqa.selenium.json.JsonTypeCoercer.<init>(JsonTypeCoercer.java:53)
    at org.openqa.selenium.json.Json.<init>(Json.java:37)
    at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:99)
    at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:93)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at com.mycompanynamereplaced.cucumber.commons.webdriver.LocalWebDriverFacade.createChromeWebDriver(LocalWebDriverFacade.java:99)
  • Related