更改的Watir Mozilla Firefox浏览器preferences [英] Watir Changing Mozilla Firefox Preferences

查看:217
本文介绍了更改的Watir Mozilla Firefox浏览器preferences的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Watir的一些事情对我来说自动运行Ruby脚本。我试图自动一些文件保存到某个目录。所以,在我的Mozilla的设置,设置我的默认下载目录要说桌面,选择自动保存文件。

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.

这些变化,但是,是不是当我开始运行我的脚本体现。这似乎是preferences恢复到默认值。我已经包括以下

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.

和打开一个新的Firefox实例:

and open a new firefox instance with:

browser = Watir::Browser.new(:firefox)

这是为什么preferences将这个被重新设置任何想法?或者什么,我试图做任何其他的想法? (自动保存文件)。

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).

感谢

推荐答案

使用的webdriver每个浏览器实例,这就是为什么preferences似乎是复位干净的轮廓。你可以告诉它使用您的默认配置文件:

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:

Watir::Browser.new :firefox, :profile => "default" 

或启动浏览器之前编程调整配置文件preferences:

or tweak profile preferences programatically before launching the browser:

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

Watir::Browser.new :firefox, :profile => profile

有关配置自动下载文件的示例,请参见本节的硒维基。

For an example of configuring automatic file downloads, see this section on the Selenium wiki.

这篇关于更改的Watir Mozilla Firefox浏览器preferences的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆