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

如何在Robot Framework脚本中配置Firefox二进制路径解决启动异常

Robot Framework指定Firefox二进制文件路径的解决方法

遇到这个错误是因为Selenium无法找到Firefox的默认安装路径,你可以通过以下两种方式在脚本中指定Firefox的绝对路径:

方法一:通过Desired Capabilities配置

先定义Firefox二进制文件的路径变量,再创建对应的浏览器能力,最后带着能力打开浏览器:

*** Settings ***
Library     SeleniumLibrary

*** Variables ***
${URL}          https://www.google.com
${Browser}      firefox
# 替换成你本地Firefox的实际绝对路径
${FIREFOX_BINARY}    C:\\Program Files\\Mozilla Firefox\\firefox.exe

*** Test Cases ***
Testing with Browser
    ${firefox_capabilities}=    Create Dictionary    moz:firefoxOptions=${{"binary": "${FIREFOX_BINARY}"}}
    Open Browser    ${URL}    ${Browser}    desired_capabilities=${firefox_capabilities}

方法二:直接通过firefox_options参数指定

利用Firefox的命令行参数--binary直接指定路径,写法更简洁:

*** Settings ***
Library     SeleniumLibrary

*** Variables ***
${URL}          https://www.google.com
${Browser}      firefox
# 替换成你本地Firefox的实际绝对路径
${FIREFOX_BINARY}    C:\\Program Files\\Mozilla Firefox\\firefox.exe

*** Test Cases ***
Testing with Browser
    Open Browser    ${URL}    ${Browser}    firefox_options=--binary=${FIREFOX_BINARY}

注意事项:

  • Windows系统下路径中的反斜杠要写成双反斜杠\\,或者改用正斜杠/;
  • Mac系统的Firefox路径一般为/Applications/Firefox.app/Contents/MacOS/firefox;
  • Linux系统的Firefox路径通常是/usr/bin/firefox,需根据实际安装位置调整。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 04:22:37