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

如何在Robot Framework的SeleniumLibrary中指定特定Firefox路径

解决Robot Framework指定特定Firefox版本路径的问题

方法1:直接通过Open Browser关键字指定路径

使用Open Browser关键字的firefox_binary参数,直接传入目标Firefox可执行文件的绝对路径即可。

示例代码:

*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Run Test With Specific Firefox
    # Windows路径需转义反斜杠,或用单斜杠替代
    ${target_firefox_path}    Set Variable    C:\\Program Files\\Mozilla Firefox 115\\firefox.exe
    # Linux/macOS路径示例:/usr/local/firefox-115/firefox
    Open Browser    https://www.example.com    firefox    firefox_binary=${target_firefox_path}
    # 执行测试步骤
    Close Browser

方法2:通过FirefoxOptions配置路径

先创建FirefoxOptions对象,调用set_binary方法指定路径,再传入Open Browser关键字。

示例代码:

*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Configure Firefox Path Via Options
    ${firefox_options}    Create Webdriver Firefox Options
    Call Method    ${firefox_options}    set_binary    C:\\Program Files\\Mozilla Firefox 115\\firefox.exe
    Open Browser    https://www.example.com    firefox    options=${firefox_options}
    # 执行测试步骤
    Close Browser

注意事项

  • Windows系统路径可使用双反斜杠\\转义,或直接用单斜杠/;Linux/macOS使用常规文件路径即可。
  • 确保指定的Firefox可执行文件具备运行权限,且版本与当前使用的geckodriver、SeleniumLibrary兼容。

内容的提问来源于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.11 04:22:05