专题开篇:Selenium 3.0对于Firefox浏览器启动的改变(geckodriver)

让你害怕的不是未知的未来,而是不断重複著过去的错误。

专题开篇:Selenium 3.0对于Firefox浏览器启动的改变(geckodriver)_第1张图片
Selenium 3.0 is Out Now!

发现问题:为什么从Selenium2.x切换到Selenium 3.0驱动不了Firefox浏览器?

  • Selenium2.x版本驱动Firefox浏览器方法
专题开篇:Selenium 3.0对于Firefox浏览器启动的改变(geckodriver)_第2张图片
Selenium2.x驱动Firefox
  • 执行报错如下:
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.(FirefoxDriver.java:247)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:242)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:238)
    at org.openqa.selenium.firefox.FirefoxDriver.(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 ”系统参数初始化设置

执行代码后,控制台报出“java.lang.IllegalStateException”错误,提示Firefox驱动必须以“webdriver.gecko.driver”环境变量初始化;如果需要更多信息,请点击https://github.com/mozilla/geckodriver;Firefox驱动文件版本下载地址,请点击https://github.com/mozilla/geckodriver/releases。

专题开篇:Selenium 3.0对于Firefox浏览器启动的改变(geckodriver)_第3张图片
按操作系统罗列驱动文件
  • 完善代码:加载geckodriver驱动
专题开篇:Selenium 3.0对于Firefox浏览器启动的改变(geckodriver)_第4张图片
加载驱动文件
##以下为完善代码后控制台的日志##
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更新说明延伸

  • 官方博客
专题开篇:Selenium 3.0对于Firefox浏览器启动的改变(geckodriver)_第5张图片
Selenium官方博客

==> 点击我的博客

你可能感兴趣的:(专题开篇:Selenium 3.0对于Firefox浏览器启动的改变(geckodriver))