我不想在这里做太多事情。
我只是想运行 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/