0

Unable to set custom download directory path when using

Selenium Webdriver 3.3.0
Watir-Webdriver 0.9.9
Firefox 52 , geckodriver 0.15
Windows 7, Ruby 2.1.9

Code looks like this.

EXPORTS_DIR = 'exports'
EXPORTS_PATH_BROWSER = File.realpath(EXPORTS_DIR)

firefox_profile = Selenium::WebDriver::Firefox::Profile.new
firefox_profile['browser.download.dir'] = EXPORTS_PATH_BROWSER
firefox_profile['browser.download.animateNotifications'] = false
firefox_profile['browser.download.panel.shown'] = false
firefox_profile['browser.download.useDownloadDir'] = true

FIREFOX_CAPS = Selenium::WebDriver::Remote::Capabilities.firefox(
    firefoxOptions: {
        args:  ['--always-authorize-plugins'],
        prefs: firefox_profile
    }
)

browser = Watir::Browser.new( firefox:, desired_capabilities: FIREFOX_CAPS)

I get Dialog to save/open file, which I don't want, and file is not downloaded. so there are 2 issues

  1. File Dialog should not appear
  2. File should be downloaded to given 'exports' directory.

1 Answers1

0

Apart from mentioning which folder to use for download, you need to tell Firefox that it needs to use custom download location. That you can do using the code below:-

profile['browser.download.folderList'] = 2
profile['browser.download.dir'] = download_dir
PaulDaviesC
  • 1,161
  • 3
  • 16
  • 31