2014-09-25 84 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

相關問題