您的位置:首页 > 编程语言 > Python开发

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

2017-01-18 10:23 495 查看
Firefox 45版本以上使用selenium-3.0.1无法直接启动需要如下步骤:

(1)    下载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)
from selenium import webdriver
fromselenium.webdriver.common.desired_capabilities import DesiredCapabilities
fromselenium.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 45版本以上使用selenium-3.0.1无法直接启动需要如下步骤:

(1)    下载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)
from selenium import webdriver
fromselenium.webdriver.common.desired_capabilities import DesiredCapabilities
fromselenium.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')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: