selenium - NoClassDefFound错误: org/apache/http/HttpEntity in Selenium for FirefoxDriver

标签 selenium

我不想在这里做太多事情。

我只是想运行 Selenium 网站中给出的示例,打开 Google 页面并在编辑框中输入搜索字符串

但我收到以下错误:

*> 线程“main”中出现异常

java.lang.NoClassDefFoundError: org/apache/http/client/ClientProtocolException at org.openqa.selenium.ie.InternetExplorerDriver.setup(InternetExplorerDriver.java:92) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:56) at com.testscripts.Selenium2Example.main(Selenium2Example.java:16)*

我不知道这个 ClientProtocolException 是什么 类在哪里以及在哪里可以找到它。

请问你们中有人可以帮忙吗?

代码是

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.ie.*;

public class Selenium2Example  {
    public static void main(String[] args) {
        // Create a new instance of the Firefox driver
        // Notice that the remainder of the code relies on the interface, 
        // not the implementation.
        System.setProperty("webdriver.firefox.bin", "C:\\Documents and Settings\\Vikas Kashyap\\Local Settings\\Application Data\\Mozilla Firefox\\firefox");

        WebDriver driver = new FirefoxDriver();

        //WebDriver driver = new InternetExplorerDriver();

        // And now use this to visit Google
        driver.get("http://www.google.com");

        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));

        // Enter something to search for
        element.sendKeys("Cheese!");

        // Now submit the form. WebDriver will find the form for us from the element
        element.submit();

        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());


        //Close the browser
        driver.quit();

    }
}

问候,
维卡斯

最佳答案

感谢您的回复。

我发现了我所犯的错误。

我使用 Eclipse 作为我的 IDE。 在外部引用的 JAR 文件列表中,我包含了“selenium-java-2.0b3.jar”

实际上我必须包含“selenium-server-standalone-2.0b3.jar”

Selenium 网站并没有真正说明要为服务器下载哪个 jar 文件!这造成了所有的困惑。

使用正确的 jar 文件,就不会再出现“NoClassDefFoundError”。

问候 维卡斯

关于selenium - NoClassDefFound错误: org/apache/http/HttpEntity in Selenium for FirefoxDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6018275/

相关文章:

java - Selenium 不适用于歌剧

c# - Selenium Webdriver C# Sendkeys (Keys.Arrowdown)

spring-boot - Selenium 4.1 和 Spring boot Web 驱动程序版本问题

Selenium 脚本

java - 使用 Selenium WebDriver 访问 HTTPS

java - 如何在与 Selenium 相同的选项卡中打开新 URL,但以某种方式编辑 URL?

Java Selenium Webdriver - 将文本发送到字段不会触发 angularjs 搜索字段

javascript - 有没有办法使用 WebDriver 自动触发 setTimeout 事件?

java - 带有自定义 ExpectedCondition 的 NullPointerException

java - Selenium 与 Java : Elements in a pop-up are not recognized