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

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

问题描述

我从这里安装了 JDK:http:///www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html(此版本适用于 windows x64:Java SE Development Kit 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 构建路径 -> 库选项卡 -> 添加外部 JAR... -> 我转到SeleniumDriversJava"库(在那里我保存了所有的 JARS)我下载了)-> 我检查了那里的所有文件:这些文件

Then in eclipse I click on my project -> properties ->Java Build Path -> Libraries tab -> Add External JARs... -> I go to "SeleniumDriversJava" 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:SeleniumDrivers

I unzipped it and saved it here: C:SeleniumDrivers

这是我的脚本:

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
");

        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.NoClassDefFoundErrorJRE 找不到 Class 时观察到.

简而言之,所需的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 独立服务器 早期版本相关的 jar 包 &Selenium Java 客户端
  2. 仅导入 selenium-server-standalone-3.7.0.
  3. 在您的 IDE 中的 Project 菜单中,选择选项 Build Automatically 并为所有对象执行 Clean 选项您的项目.
  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天全站免登陆