Watir 更改 Mozilla Firefox 首选项
我正在使用 Watir 运行 Ruby 脚本来自动执行一些操作。我正在尝试自动将一些文件保存到某个目录。因此,在我的 Mozilla 设置中,我将默认下载目录设置为桌面并选择自动保存文件。
然而,当我开始运行脚本时,这些更改并未反映出来。似乎首选项恢复为默认值。我已包含以下内容
require "rubygems" # Optional.
require "watir-webdriver" # For web automation.
require "win32ole" # For file save dialog.
并打开一个新的 Firefox 实例:
browser = Watir::Browser.new(:firefox)
关于为什么首选项会因此而推迟的任何想法?或者对于我想做的事情有什么替代想法吗? (自动保存文件)。
谢谢
I'm running a Ruby script using Watir to automate some things for me. I'm attempting to automatically save some files to a certain directory. So, in my Mozilla settings I set my default download directory to say the desktop and choose to automatically save files.
These changes, however, are not reflected when I begin to run my script. It seems like the preferences revert back to default. I've included the following
require "rubygems" # Optional.
require "watir-webdriver" # For web automation.
require "win32ole" # For file save dialog.
and open a new firefox instance with:
browser = Watir::Browser.new(:firefox)
Any ideas on why the preferences would be set back by this? Or any alternative ideas for what I am trying to do? (Automatically save files).
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WebDriver 为每个浏览器实例使用一个干净的配置文件,这就是首选项似乎被“重置”的原因。您可以告诉它使用默认配置文件:
或在启动浏览器之前以编程方式调整配置文件首选项:
有关配置自动文件下载的示例,请参阅 此部分。
WebDriver uses a clean profile for each browser instance, which is why the preferences appear to be "reset". You can tell it to use your default profile:
or tweak profile preferences programatically before launching the browser:
For an example of configuring automatic file downloads, see this section on the Selenium wiki.
的下载位置的默认 Watir 首选项
更改chrome
for firefox
注意:为了能够从 Rails 应用程序中轻松访问 Rails.root/lib 文件夹,您需要将此代码或类似内容添加到您的配置/应用程序中.rb 文件:
了解更多信息:http://watirwebdriver.com/browser-downloads/
change default Watir preferences for download location
for chrome
for firefox
note: to be be able to access the Rails.root/lib folder easily from within your rails app, you'll need to add this code or something like it to your config/application.rb file:
for more information: http://watirwebdriver.com/browser-downloads/