简体   繁体   中英

Unable to set download directory path with Firefox using Watir-Webdriver

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM