如何在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
相关产品推荐
相关产品推荐

