Reputation: 13
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class TestFindingElement {
public static void main(String[] args) {
WebDriverManager.chromedriver().setup();
WebDriver driver=new ChromeDriver();
driver.get("http://google.com");
}
}
When I execute the above code in the eclipse. Throwing the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hc/core5/http/ClassicHttpRequest at testcases.TestFindingElement.main(TestFindingElement.java:14) Caused by: java.lang.ClassNotFoundException: org.apache.hc.core5.http.ClassicHttpRequest at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 1 more
I check the classpath and did refresh the project still getting the same error. however, When I ran the simple print statement no error will be display. please help me I am so frustrated with the error for two days.
Upvotes: 1
Views: 1701
Reputation: 1
In this program "WebDriverManager.chromedriver().setup();" this line will not work on only java,
1.Try via maven and java : if you are using maven-java-selenium go with already used line of "WebDriverManager.chromedriver().setup();" and add dependency mentioned below, https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager/5.3.0
if its not maven add a jar of "WebDriverManager" in your java project
Else instead of this line "WebDriverManager.chromedriver().setup();", you can go with "System.setproperty("webdriver.chrome.driver","mention your chromedriver path which already have in your system");
Upvotes: 0
Reputation: 29
If it's a maven project, add this dependency to your POM.xml:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
Upvotes: 1