Ruby 无法使用Watir Webdriver设置Firefox的下载目录路径
使用时无法设置自定义下载目录路径Ruby 无法使用Watir Webdriver设置Firefox的下载目录路径,ruby,selenium,selenium-webdriver,watir-webdriver,geckodriver,Ruby,Selenium,Selenium Webdriver,Watir Webdriver,Geckodriver,使用时无法设置自定义下载目录路径 Selenium Webdriver 3.3.0 Watir-Webdriver 0.9.9 Firefox 52 , geckodriver 0.15 Windows 7, Ruby 2.1.9 代码看起来像这样 EXPORTS_DIR = 'exports' EXPORTS_PATH_BROWSER = File.realpath(EXPORTS_DIR) firefox_profile = Selenium::WebDriver::Firefox::P
Selenium Webdriver 3.3.0
Watir-Webdriver 0.9.9
Firefox 52 , geckodriver 0.15
Windows 7, Ruby 2.1.9
代码看起来像这样
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)
我得到一个对话框来保存/打开文件,我不想这样,但文件并没有下载。
因此有两个问题
除了提到要使用哪个文件夹下载外,您还需要告诉Firefox它需要使用自定义下载位置。您可以使用以下代码执行此操作:-
profile['browser.download.folderList'] = 2
profile['browser.download.dir'] = download_dir
这可能有助于u-我尝试了该线程中提到的解决方案,但它不起作用