Selenium Webdriver + Java-Eclipse:java.lang.NoClassDefFoundError [英] Selenium Webdriver + Java - Eclipse: java.lang.NoClassDefFoundError

查看:95
本文介绍了Selenium Webdriver + Java-Eclipse:java.lang.NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从此处安装JDK: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html (适用于Windows x64的此版本:Java SE开发套件8u151)

I installed JDK from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html (This version for windows x64: Java SE Development Kit 8u151)

我从这里下载了eclipse: http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/oxygenr (Windows 64位)

I downloaded eclipse from here: http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/oxygenr (Windows 64-bit)

我在Eclipse中打开了一个新项目:File-> New-> Java Project

I opened a new project in eclipse: File->New->Java Project

然后我从这里下载Selenium Java Jars: http://www.seleniumhq.org/download/ ---> Java语言

Then I downloaded Selenium Java Jars from here: http://www.seleniumhq.org/download/ ---> java language

然后在eclipse中单击我的项目->属性-> Java Build Path->库选项卡->添加外部JAR ...->我转到"SeleniumDrivers \ Java"库(在那里我保存了所有我下载了)->我检查了所有文件: 这些文件

Then in eclipse I click on my project -> properties ->Java Build Path -> Libraries tab -> Add External JARs... -> I go to "SeleniumDrivers\Java" library (there I saved all the JARS that I downloaded) -> I checked all the files there: these files

我点击确定"并在eclipse中创建了一个新类

I clicked on "ok" and created a new class in eclipse

然后我从此处下载了chromedriver: http://www.seleniumhq.org/download

Then I downloaded chromedriver from here: http://www.seleniumhq.org/download

我解压缩并将其保存在这里:C:\ Selenium \ Drivers

I unzipped it and saved it here: C:\Selenium\Drivers

这是我的脚本:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class MainClass {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("hi there\n");

        System.setProperty("webdriver.chrome.driver", 
        "C:/Selenium/Drivers/chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.facebook.com");
    }

}

如您所见,这是一个非常基本的脚本,可打开chrome浏览器并导航到facebook.

As you can see, this is a very basic script which opens chrome browser and navigate to facebook.

我运行此脚本并收到此错误:

I run this script and got this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/config/RegistryBuilder
    at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:69)
    at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:57)
    at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:60)
    at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:242)
    at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.<init>(ApacheHttpClient.java:219)
    at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:93)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:72)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:63)
    at org.openqa.selenium.chrome.ChromeDriverCommandExecutor.<init>(ChromeDriverCommandExecutor.java:36)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at MainClass.main(MainClass.java:11)
Caused by: java.lang.ClassNotFoundException: org.apache.http.config.RegistryBuilder
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 13 more

我不知道如何解决此问题,请您帮忙解决它,以便我可以运行基本脚本?

I don't know how to resolve this issue, can you please help to solve it so that I will be able to run my basic script?

推荐答案

java.lang.NoClassDefFoundError.

简单来说,所需的importsjar文件不可用.在快照中,您分享了它的明显证据,即您已尝试添加与 Java Client 相关的jar.

In simple words the required imports or jar files are not available. From the snapshot you have shared its pretty much evident that you have tried to add the Java Client related jars.

在这种情况下,您需要执行以下步骤:

In this case you need to follow the following steps:

  1. 删除所有引用早期版本的 Selenium独立服务器的罐子. Selenium Java客户端
  2. 仅导入 selenium-server-standalone-3.7.0 .
  3. Project 菜单的 IDE 中,选择选项自动构建并为所有项目执行Clean选项./li>
  4. 执行测试.
  1. Remove all the jars referring to previous versions of Selenium standalone server & Selenium Java client
  2. Import only the selenium-server-standalone-3.7.0.
  3. In your IDE within Project menu, select the option Build Automatically and execute the Clean option for all of your Projects.
  4. Execute your Test.

这篇关于Selenium Webdriver + Java-Eclipse:java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆