Firefox  

GeckoDriver

要使用 Firefox,请确保您 使用适当的驱动程序

启动 Firefox

b = Watir::Browser.new :firefox

Firefox 选项

注意:本文档已更新至 Watir 6.19,并专注于支持 Selenium 4 的更新。

对于非浏览器特定的功能,请查看我们的 功能指南 除了这些功能之外,还有 许多特定于 Firefox 的设置 将改变 Firefox 在测试运行期间的操作方式。

当您传入一个基于 Selenium 的 Firefox::Options 的哈希时,Watir 将为您构建选项。

常用的设置包括

  • :args - 启动 Firefox 时使用的命令行参数数组
  • :binary - 表示要使用的 Firefox 浏览器可执行文件路径的字符串
  • :profile - 编码的配置文件字符串或 Firefox::Profile 实例
  • :log_level - 表示 geckodriver 的所需日志级别的字符串或符号
  • :prefs - 一个哈希,每个条目包含首选项的键及其值

Firefox 配置文件

您可以指定要使用的现有配置文件,例如您的“默认”配置文件

b = Watir::Browser.new :firefox, options: {profile: 'default'}

您还可以使用可以在 Firefox 的 about:config 面板中配置的任何选项,在每次测试运行时创建一个新的 Firefox 配置文件

例如

profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.dir'] = '/tmp/webdriver-downloads'
profile['browser.download.folderList'] = 2
profile['browser.helperApps.neverAsk.saveToDisk'] = 'application/pdf'

b = Watir::Browser.new :firefox, options: {profile: profile}

最后更新时间:2021 年 3 月 12 日