简体   繁体   English

无法使用Watir-Webdriver在Firefox中设置下载目录路径

[英]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. 除了提及要使用哪个文件夹下载外,您还需要告诉Firefox它需要使用自定义下载位置。 That you can do using the code below:- 您可以使用以下代码进行操作:-

profile['browser.download.folderList'] = 2
profile['browser.download.dir'] = download_dir

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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