I am trying to run a simple test with selenium, but I am getting ClassNotFoundException when I run my test and I don\'t know what dependency to import to solve this issue.
ClassNotFoundException in Java is a subclass of java.lang.Exception and occurs when Java Virtual Machine tries to load a particular class and doesn't finds the requested class in classpath. It is a checked Exception and explicit Exception handling methods are required to what can possibly be throwing ClassNotFoundException either by using try-catch
block or by using throws
clause.
As per the Java Docs ClassNotFoundException comes in following cases:
Class.forName()
method and .class
file or binary of class is not available in classpath.findSystemClass()
method.loadClass()
method of class ClassLoader in Java.ClassNotFoundExcepiton
can arise only when JVM tries to load a class at run-time but nothing related to compile time which is unlike NoClassDefFoundError. This is because till run time JVM doesn't know about this Class and it can only be done by above specified method or by employing Reflection to read the name of class from some configuration and then load the class specified on those configuration file.
The error does gives us a hint what is going wrong as follows :
Caused by: java.lang.ClassNotFoundException: org.apache.xml.utils.PrefixResolver
As per the pom.xml you have shared clearly the <version>x.y.z</version>
tag is missing. You need to change the as follows :
selenium-api
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.10.0</version>
</dependency>
selenium-htmlunit-driver
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-htmlunit-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.52.0</version>
</dependency>
As you are using spring-boot 1.5.10 additionally you may also require to add either of the following <dependency>
:
selenium-java
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.10.0</version>
</dependency>
selenium-server
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.10.0</version>
</dependency>