Watir更改Mozilla Firefox首选项

Vin*_*sso 5 ruby scripting automation screen-scraping watir

我正在运行一个使用Watir的Ruby脚本来为我自动化一些东西.我正在尝试自动将某些文件保存到某个目录.因此,在我的Mozilla设置中,我将默认下载目录设置为说出桌面并选择自动保存文件.

但是,当我开始运行脚本时,这些更改不会反映出来.似乎首选项恢复为默认值.我已经包括以下内容

require "rubygems"         # Optional.
require "watir-webdriver"  # For web automation.
require "win32ole"         # For file save dialog.
Run Code Online (Sandbox Code Playgroud)

并打开一个新的firefox实例:

browser = Watir::Browser.new(:firefox)
Run Code Online (Sandbox Code Playgroud)

关于为什么偏好会因此而退缩的任何想法?或者我正在尝试做什么的其他想法?(自动保存文件).

谢谢

jar*_*rib 8

WebDriver为每个浏览器实例使用干净的配置文件,这就是首选项似乎"重置"的原因.您可以告诉它使用您的默认配置文件:

Watir::Browser.new :firefox, :profile => "default" 
Run Code Online (Sandbox Code Playgroud)

或者在启动浏览器之前以编程方式调整配置文件首选项:

profile = Selenium::WebDriver::Firefox::Profile.new
profile['some.preference'] = true
profile.add_extension "/path/to/some/extension.xpi"

Watir::Browser.new :firefox, :profile => profile
Run Code Online (Sandbox Code Playgroud)

有关配置自动文件下载的示例,请参阅Selenium wiki上的此部分.