Eclipse 执行selenium web驱动程序时获取异常
我正在执行简单的java程序,并尝试执行我的第一个selenium脚本Eclipse 执行selenium web驱动程序时获取异常,eclipse,testing,selenium,selenium-webdriver,Eclipse,Testing,Selenium,Selenium Webdriver,我正在执行简单的java程序,并尝试执行我的第一个selenium脚本 public static void main(String[] args) { // Create a new instance of the html unit driver // Notice that the remainder of the code relies on the interface, // not the implementation.
public static void main(String[] args) {
// Create a new instance of the html unit driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new HtmlUnitDriver();
// 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());
driver.quit();
}
以下是我添加的依赖项:
但是在运行了这段代码之后,我在eclipse中遇到了这个异常
java.lang.ClassNotFoundException: org.apache.xerces.xni.XNIException
ClassNotFoundException
通常在指定的类路径中找不到类文件时发生。因此,请尝试删除xerces.jar并再次添加它。为什么要使用xerces.jar,我认为运行selenium脚本不需要它。删除它,然后再试一次。我以前在没有xerces.jar的情况下做过,但它抛出了我提到的异常。所以我加了这个罐子。现在我再次移除了罐子,但得到了相同的异常:(