Watir Change Mozilla Firefox Settings

I am using a Ruby script, using Watir to automate some things for me. I am trying to automatically save some files in a specific directory. Thus, in my Mozilla settings, I set my default download directory to say β€œdesktop” and choose to automatically save files.

These changes, however, are not reflected when I run my script. It seems that the settings are reverting to default. I have included the following

require "rubygems"         # Optional.
require "watir-webdriver"  # For web automation.
require "win32ole"         # For file save dialog.

and open a new instance of firefox with

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

Any ideas on why preferences will be discarded by this? Or any alternative ideas for what I'm trying to do? (Automatically save files).

thank

+5
2

WebDriver , "reset". , :

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

. Selenium.

+7

profile = Selenium::WebDriver::Chrome::Profile.new
download_dir = File.join(Rails.root, 'lib', 'assets')
profile['download.default_directory'] = download_dir
profile[download.prompt_for_download] = false
@b = Watir::Browser.new :chrome, :profile => profile

firefox

profile = Selenium::WebDriver::Firefox::Profile.new    
download_dir = File.join(Rails.root, 'lib', 'assets')
profile['browser.download.dir'] = download_dir
profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv,application/pdf"
@b = Watir::Browser.new. :firefox, :profile => profile

: Rails.root/lib rails, - config/application.rb:

config.autoload_paths += Dir["#{config.root}/lib/**/"]

: http://watirwebdriver.com/browser-downloads/

+2

All Articles