Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watir Changing Mozilla Firefox Preferences

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

like image 907
Vincent Russo Avatar asked Jul 03 '11 17:07

Vincent Russo


1 Answers

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" 

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.

like image 108
jarib Avatar answered Sep 22 '22 16:09

jarib