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

本文介绍如何解决Firefox45版本以上与selenium-3.0.1的兼容问题,包括下载geckodriver.exe并正确设置路径,以及通过FirefoxBinary指定Firefox的可执行文件位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值