我正在使用 Watir 运行一个 Ruby 脚本来为我自动化一些事情。我试图自动将一些文件保存到某个目录。因此,在我的 Mozilla 设置中,我将默认下载目录设置为桌面并选择自动保存文件。
但是,当我开始运行我的脚本时,这些更改并没有反射(reflect)出来。似乎首选项恢复为默认值。我已经包括以下内容
require "rubygems" # Optional.
require "watir-webdriver" # For web automation.
require "win32ole" # For file save dialog.
并打开一个新的 firefox 实例:
browser = Watir::Browser.new(:firefox)
关于为什么偏好会因此而受挫的任何想法?或者对我正在尝试做的事情有任何替代想法? (自动保存文件)。
谢谢
最佳答案
WebDriver 为每个浏览器实例使用一个干净的配置文件,这就是首选项显示为“重置”的原因。您可以告诉它使用您的默认配置文件:
Watir::Browser.new :firefox, :profile => "default"
或在启动浏览器之前以编程方式调整配置文件首选项:
profile = Selenium::WebDriver::Firefox::Profile.new
profile['some.preference'] = true
profile.add_extension "/path/to/some/extension.xpi"
Watir::Browser.new :firefox, :profile => profile
有关配置自动文件下载的示例,请参阅 this section在 Selenium wiki 上。
关于ruby - Watir 更改 Mozilla Firefox 首选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6564392/