Python Selenium 启动新版本Firefox失败问题解决方案

来源:互联网 发布:公章制作软件 编辑:程序博客网 时间:2024/05/29 09:27

Firefox 45版本以上使用selenium-3.0.1无法直接启动需要如下步骤:



firefox历年版本的官方镜像地址:
https://download-installer.cdn.mozilla.net/pub/firefox/releases/
火狐所有的geckodriver.exe驱动大全
https://github.com/mozilla/geckodriver/releases



解压后放置到

1.查看C:\Python27\Lib\site-packages\selenium\webdriver\firefox中的webdriver.py,在def_init_函数中,executable_path="geckodriver",之前搭建的环境上是executable_path="wires"

2.geckodriver是一原生态的第三方浏览器,对于selenium3.x版本都会使用geckodriver来驱动firefox,所以需要下载geckodriver.exe,下载地址:https://github.com/mozilla/geckodriver/releases

3.放在C:\Python27(查看环境变量path中是否添加C:\Python27该路径)。


2)  python代码:


from selenium import webdriverfromselenium.webdriver.common.desired_capabilities import DesiredCapabilitiesfromselenium.webdriver.firefox.firefox_binary import FirefoxBinary binary = FirefoxBinary(r'C:\ProgramFiles (x86)\Mozilla Firefox\firefox.exe')driver =webdriver.Firefox(firefox_binary=binary)driver.get('http://www.google.com')


 


firefox历年版本的官方镜像地址:
https://download-installer.cdn.mozilla.net/pub/firefox/releases/
阅读全文
0 0
原创粉丝点击