美文网首页
关于Selenium3.0 怎么调用firefox WebDri

关于Selenium3.0 怎么调用firefox WebDri

作者: Moddy | 来源:发表于2017-08-07 16:34 被阅读0次

    时至今日,Selenium已经到了3.3.1版了(2017年3月7日)。

    自从Selenium3发布以来,火狐浏览器(Selenium支持火狐的技术最为成熟,因为可以方便获取从而控制网页信息,也是测试人员最喜欢用的浏览器之一)成为了一个普遍的问题。

    因为Selenium3不支持向前支持火狐浏览器了,40以后版本的火狐,运行会出现问题。

    如运行报错:

    lenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

    这是因为在Firefox高版本需要使用 geckodriver 来驱动,不再使用Seleniu默认自带的Firefox webdriver。

    我们只需要在下面这个地址下载 geckodriver 并将 其所在的路径设为环境变量即可解决。

    https://github.com/mozilla/geckodriver/releases

    当报如下错误信息时,则是

    selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location,

    no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

    这时我们需要指定Firefox浏览器程序路径。

    binary = FirefoxBinary('D:\\Firefox\\Firefox\\firefox.exe')

    driver = webdriver.Firefox(firefox_binary=binary)

    注:提示找不到"firefoxBinary"可以通过下面语句导入    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

    这样就能正常使用了。

    另一个处理办法是将firefox的安装路径,直接增加到 python35\Lib\site-packages\selenium\webdriver\firefox 目录下的 firefox_binary.py文件中,如下图所示,然后driver = webdriver.Firefox()调用

    相关文章

      网友评论

          本文标题:关于Selenium3.0 怎么调用firefox WebDri

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