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

如何解决Firefox WebDriver的firefox_binary参数传入错误?

解决方法

问题根源是Selenium 4.x版本彻底重构了浏览器驱动和选项的初始化方式,原来的firefox_binary和executable_path参数已经不再被WebDriver构造函数支持,得换成新的写法:

  1. 用FirefoxOptions类指定浏览器二进制文件路径
  2. 用Service类管理驱动文件路径
  3. 在Create webdriver中传入这两个对象

修改后的Robot Framework代码:

Open Page
    [Arguments]  ${serverurl}  ${browser}  ${browserpath}  ${driverpath}
    ${firefox_options}=  Evaluate  from selenium.webdriver.firefox.options import Options; Options()
    Call Method    ${firefox_options}    set_binary    ${browserpath}
    ${firefox_service}=  Evaluate  from selenium.webdriver.firefox.service import Service; Service(${driverpath})
    Create Webdriver  ${browser}  options=${firefox_options}  service=${firefox_service}
    Go To  ${serverurl}
    Maximize Browser Window

关键改动说明

  • 用Evaluate关键字导入并初始化Selenium的Options和Service类
  • 通过Call Method调用set_binary方法设置Firefox浏览器路径,替代原来的firefox_binary参数
  • 用Service类封装驱动路径,替代原来的executable_path参数
  • 在Create Webdriver中通过options和service参数传入配置

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 16:00:56