美文网首页神奇的自动化和性能测试我爱编程
专题开篇:Selenium 3.0对于Firefox浏览器启动的

专题开篇:Selenium 3.0对于Firefox浏览器启动的

作者: Amio_ | 来源:发表于2016-12-08 20:37 被阅读7308次

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

    Selenium 3.0 is Out Now!

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

    • Selenium2.x版本驱动Firefox浏览器方法
    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.<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 ”系统参数初始化设置

    执行代码后,控制台报出“java.lang.IllegalStateException”错误,提示Firefox驱动必须以“webdriver.gecko.driver”环境变量初始化;如果需要更多信息,请点击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更新说明延伸

    • 官方博客
    Selenium官方博客

    ==> 点击我的博客

    相关文章

      网友评论

      • 灬雨纷飞:配置的selenium3.0使用了你说的这个办法,但是我代码报错如下,帮忙看一下,非常感谢
        Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN10
        Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
        System info: host: 'WIN10-612221128', ip: '192.168.10.106', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
        Driver info: driver.version: FirefoxDriver
        at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:75)
        at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:60)
        at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:56)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:127)
        at LoginTest.main(LoginTest.java:21)
        25134de4b35c:我能打开浏览器但是不能打开网页
        报错
        1496731604926 addons.manager ERROR startup failed: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIFile.create]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: resource://gre/modules/FileUtils.jsm :: FileUtils_getDir :: line 70" data: no] Stack trace: FileUtils_getDir()@resource://gre/modules/FileUtils.jsm:70 < FileUtils_getFile()@resource://gre/modules/FileUtils.jsm:42 < validateBlocklist()@resource://gre/modules/AddonManager.jsm:671 < startup()@resource://gre/modules/AddonManager.jsm:834 < startup()@resource://gre/modules/AddonManager.jsm:3129 < observe()@resource://gre/components/addonManager.js:65
        JavaScript error: resource://gre/modules/AddonManager.jsm, line 1657: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
        1496731608572 Marionette INFO Listening on port 58392
        JavaScript error: resource://gre/modules/AddonManager.jsm, line 2570: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
        Jun 06, 2017 2:46:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
        信息: Detected dialect: W3C
        Amio_:@灬雨纷飞 这个意思是可能你的火狐浏览器装的不是默认路径。
      • Amio_:专题第一篇,虽然挺基础,但也是一道selenium3.0不一样的旅途。。

      本文标题:专题开篇:Selenium 3.0对于Firefox浏览器启动的

      本文链接:https://www.haomeiwen.com/subject/gfpjmttx.html