The path to the driver executable must be set by the webdriver.gecko.driver system property;

來源:互聯網
上載者:User

標籤:tar   ccf   ram   can   create   運行   more   安裝   pat   

 

今天安裝了webdriver後,編寫了一個測試小程式,但運行時控制台報了這樣的錯誤:

 1 Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases

 

解決過程:

1、查了一下,據說報這個錯是因為在selenium3中,使用Firefox需要添加驅動。於是從晚上找驅動:

下載網址1:http://download.csdn.net/detail/just_h_mao/9670229

下載網址2: https://github.com/mozilla/geckodriver/releases/tag/v0.9.0

2、

 

注意:如果firefox安裝時使用了非預設安裝路徑,則可以無法找到firefox.exe來啟動執行此指令碼的firefox瀏覽器。在new FirefoxDriver()前設定一下瀏覽器安裝路徑即可解決,如下:

 1 package helloworld; 2 import org.openqa.selenium.*; 3 import org.openqa.selenium.By.ById; 4 import org.openqa.selenium.firefox.FirefoxDriver; 5  6 public class JavaTest { 7  8     public static void main(String[] args) { 9         // TODO Auto-generated method stub10         11         WebDriver driver;12         String baseurl;13         System.setProperty("webdriver.gecko.driver", "F:\\WebDriver\\下載\\geckodriver-v0.11.1-win64\\geckodriver.exe");
14 driver=new FirefoxDriver();15 baseurl="http://www.sogou.com/";16 //開啟搜狗首頁17 driver.get(baseurl+"/");18 //在搜尋方塊輸入XX19 driver.findElement(By.id("query")).sendKeys("XX");20 //單擊搜尋按鈕21 driver.findElement(By.id("stb")).click();22 23 24 }25 26 }

但運行後還是出現錯誤: 

1495555671697    geckodriver    INFO    Listening on 127.0.0.1:30859五月 24, 2017 12:07:52 上午 org.openqa.selenium.remote.ProtocolHandshake createSession資訊: Attempting bi-dialect session, assuming Postel‘s Law holds true on the remote end1495555672392    mozprofile::profile    INFO    Using profile path C:\Users\admn\AppData\Local\Temp\rust_mozprofile.62d2gzZYduHH1495555672416    geckodriver::marionette    INFO    Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe1495555672563    geckodriver::marionette    INFO    Connecting to Marionette on localhost:180281495555677486    Marionette    INFO    Listening on port 18028五月 24, 2017 12:07:57 上午 org.openqa.selenium.remote.ProtocolHandshake createSession資訊: Detected dialect: W3CException in thread "main" org.openqa.selenium.InvalidArgumentException: Expected [object Undefined] undefined to be a stringBuild info: version: ‘unknown‘, revision: ‘1969d75‘, time: ‘2016-10-18 09:43:45 -0700‘System info: host: ‘admin‘, ip: ‘192.168.1.102‘, os.name: ‘Windows 8.1‘, os.arch: ‘amd64‘, os.version: ‘6.3‘, java.version: ‘1.8.0_31‘Driver info: org.openqa.selenium.firefox.FirefoxDriverCapabilities [{moz:profile=C:\Users\admn\AppData\Local\Temp\rust_mozprofile.62d2gzZYduHH, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0.2, platformVersion=10.0, moz:processID=14196, browserName=firefox, platformName=windows_nt}]Session ID: 7a0a1695-fe51-4d87-a720-2f7c1baa7038    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)    at java.lang.reflect.Constructor.newInstance(Unknown Source)    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:127)    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93)    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:98)    at helloworld.JavaTest.main(JavaTest.java:19)
View Code

 

The path to the driver executable must be set by the webdriver.gecko.driver system property;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.