2017-01-23 57 views
1

我正在學習硒,我剛從一個網站複製了一個簡單的java代碼並試圖運行它。但它給了我下面的錯誤。請幫我修復它。簡單的java代碼中的硒錯誤

安裝的文件:

1. Selenium api 2.44.0 
2. Selenium firefox driver 2.44.0 
3. Seleinium server stand alone 2.53.1 
4. Selenium support 2.44 
5. Firefox version - 35.1.0 

錯誤:

Exception in thread "main" java.lang.NoClassDefFoundError:
org/openqa/selenium/remote/internal/CircularOutputStream at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:59) at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:55) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:95) at Sel.OpenGoogle.main(OpenGoogle.java:6) Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.internal.CircularOutputStream at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 4 more

我的代碼:

添加硒遠程驅動器2.4.4

Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA 
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40' 
System info: host: 'PC', ip: '192.168.1.2', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_101' 
Driver info: driver.version: FirefoxDriver 
at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:72) 
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:59) 
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:55) 
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95) 
at Sel.OpenGoogle.main(OpenGoogle.java:6) 
package Sel; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
public class OpenGoogle { 
    public static void main(String args[]){ 
    WebDriver driver=new FirefoxDriver(); 
    System.out.println("Hello Google..."); 
    driver.get("http://google.com");  
    } 
} 

錯誤

+0

是的,我右鍵點擊我的項目,然後添加jar文件 –

+1

你可以添加硒遠程驅動程序jar以及再次測試。 https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver/2.7.0 –

+0

後,我添加的遠程驅動器得到這個錯誤。更新OP –

回答

0

@Stack馬克下載的Java硒2.53從這個鏈接

http://selenium-release.storage.googleapis.com/index.html?path=2.53/

刪除所有當前已安裝的jar文件並加載新的。小心不要刪除JRE系統庫。 然後一切都會正常工作。 順便問一下,你使用的是Firefox瀏覽器?我正在使用47.0.1 好處是您不必使用壁虎驅動程序。

+0

我得到這個錯誤,當我跟着你的步驟,我使用線程「主」java.lang.NoClassDefFoundError 35.0.1'異常:com /谷歌/普通/基地/功能 \t在Sel.OpenGoogle.main(OpenGoogle.java:7) 引起:拋出java.lang.ClassNotFoundException:在java.net.URLClassLoader.findClass(未知來源)com.google.common.base.Function \t \t 在java的.lang.Clas sLoader.loadClass(來源不明) \t在sun.misc.Launcher $ AppClassLoader.loadClass(來源不明) \t在java.lang.ClassLoader.loadClass(來源不明) \t ... 1更多的」 –