You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python版Selenium 4.7.2适配旧版本Firefox 47?

适配Firefox 47的Selenium项目最佳方案

Firefox 47属于pre-Marionette时代的过渡版本,和新版Firefox的驱动逻辑差异极大,直接用新版Selenium+geckodriver组合会出现大量兼容性问题,以下是最稳妥的适配方案:

一、核心适配思路

放弃新版Selenium和geckodriver,改用Selenium 2.x/早期3.x版本 + 传统FirefoxDriver的组合——这是Firefox 47原生支持的驱动方式,稳定性最高。

二、具体实现步骤

  1. 锁定兼容的Selenium版本
    安装Selenium 2.53.1(最后一个全面支持传统FirefoxDriver的稳定版),或者Selenium 3.0.1(仍保留传统驱动支持的早期3.x版本)。避免使用Selenium 3.1.x及以后的版本,这些版本已经逐步移除了对传统FirefoxDriver的支持。

  2. 使用传统FirefoxDriver
    不需要额外下载geckodriver,直接调用Selenium自带的FirefoxDriver即可,只需指定Firefox 47的安装路径:

    from selenium import webdriver
    
    # 替换为你的Firefox 47实际路径
    firefox_path = r"C:\Program Files\Mozilla Firefox 47\firefox.exe"
    driver = webdriver.Firefox(firefox_binary=firefox_path)
    
  3. 强制禁用Marionette(可选)
    若使用的是Selenium 3.x版本,默认可能会尝试启用Marionette,需手动禁用确保传统驱动生效:

    from selenium import webdriver
    
    firefox_path = r"C:\Program Files\Mozilla Firefox 47\firefox.exe"
    driver = webdriver.Firefox(firefox_binary=firefox_path, marionette=False)
    

三、关于旧版本geckodriver的可行性

可以用,但不推荐。Firefox 47对Marionette引擎的支持是实验性的,早期geckodriver(如v0.10.x版本)存在大量未修复的bug,容易出现浏览器启动失败、元素定位异常等问题。如果非要尝试,需:

  • 下载适配Firefox 47的geckodriver版本(如v0.10.0)
  • 手动启用Marionette:
    from selenium import webdriver
    
     firefox_path = r"C:\Program Files\Mozilla Firefox 47\firefox.exe"
     gecko_path = r"C:\Path\To\geckodriver.exe"
     driver = webdriver.Firefox(firefox_binary=firefox_path, executable_path=gecko_path, marionette=True)
    

内容的提问来源于stack exchange,提问作者bevilex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 18:55:30