Reputation: 2315
In some (seemingly random) cases, I get below error when working with Selenium and Chrome headless webdriver:
java.lang.NoClassDefFoundError: Could not initialize class org.openqa.selenium.WebDriverException
I guess some elements are not available in the browser which causes the exception but without an exception message I cannot be sure.
I have this in my pom.xml:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-7</version>
</dependency>
I can create a dummy instance of WebDriverException in my code. So what can be the problem?
UPDATE: I have also seen other types of Selenium exception with no messages. This is another example with stack trace:
java.lang.NoClassDefFoundError: Could not initialize class org.openqa.selenium.ElementClickInterceptedException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:196)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:129)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:167)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:123)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:501)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:238)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)
Upvotes: 0
Views: 3090
Reputation: 6188
WebDriverException
class is part of the Selenium API distribution. That dependency is missing from your POM. Aside from that, unless you are doing an evaluation, stay away from alpha versions. Always use stable releases.
Upvotes: 1