2014-09-25 82 views
1

我正在执行简单的java程序并尝试执行我的第一个硒脚本。在执行硒web驱动程序时得到异常

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(); 
    } 

这些都是我所添加的相关性:dependencies that I have added

但运行此代码后,我得到这个例外蚀。

java.lang.ClassNotFoundException: org.apache.xerces.xni.XNIException 
+0

为什么你有xerces.jar,我不认为它需要运行硒脚本。删除并再次尝试。 – 2014-09-25 10:55:27

回答

0

ClassNotFoundException大多时在指定的类路径中找不到类文件时发生。因此,请尝试删除xerces.jar并重新添加。

+1

我之前没有使用xerces.jar,但它抛出了我提到的异常。所以我加了这个罐子。现在我再次删除了jar但得到了相同的异常。 :( – rishi 2014-09-26 07:58:55

相关问题