讓你害怕的不是未知的未來,而是不斷重複著過去的錯誤坪仇。
發(fā)現(xiàn)問題:為什么從Selenium2.x切換到Selenium 3.0驅動不了Firefox瀏覽器?
-
Selenium2.x版本驅動Firefox瀏覽器方法
-
執(zhí)行報錯如下:
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
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
at org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:37)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:95)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:277)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:247)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:242)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:238)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:127)
at com.amio.automation.jianshu.Firefox.TestFirefox.main(TestFirefox.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
解決問題:從報錯堆棧切入,逐步擊破
-
報錯堆棧:driver必須以“webdriver.gecko.driver ”系統(tǒng)參數(shù)初始化設置
執(zhí)行代碼后鲁驶,控制臺報出“java.lang.IllegalStateException”錯誤,提示Firefox驅動必須以“webdriver.gecko.driver”環(huán)境變量初始化舞骆;如果需要更多信息钥弯,請點擊https://github.com/mozilla/geckodriver;Firefox驅動文件版本下載地址督禽,請點擊https://github.com/mozilla/geckodriver/releases脆霎。
-
完善代碼:加載geckodriver驅動
##以下為完善代碼后控制臺的日志##
1481199653610 geckodriver INFO Listening on 127.0.0.1:38865
十二月 08, 2016 8:20:54 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1481199654647 mozprofile::profile INFO Using profile path C:\Users\zhoup\AppData\Local\Temp\rust_mozprofile.PoufEuXzFZGx
1481199654669 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe
1481199654796 geckodriver::marionette INFO Connecting to Marionette on localhost:15736
1481199656565 Marionette INFO Listening on port 15736
十二月 08, 2016 8:21:00 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Detected dialect: W3C
Selenium 3.0更新說明延伸
-
官方博客
==> 點擊我的博客