How to disable download window in firefox with watir-webdriver?

爱⌒轻易说出口 提交于 2019-12-20 03:19:28

问题


I don't want to handle download window in Firefox or IE. I want to auto download the excel file without any download window. I have tried to set several configuration parameters for Firefox, but it didn't work. In my test I'm trying to download excel file

profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.lastDir'] = 'C:\\Downloads'
profile['browser.download.folderList'] = 2
profile['browser.download.dir'] = 'C:\\Downloads'
profile['download.prompt_for_download'] = false
profile['browser.download.manager.showWhenStarting'] = false
profile['browser.download.manager.addToRecentDocs'] = true

profile['browser.download.manager.useWindow'] = false
profile['browser.download.useDownloadDir'] = true
profile['browser.download.show_plugins_in_list'] = true
profile['browser.download.manager.openDelay'] = 100000
profile['browser.download.animateNotifications'] = false

driver = Watir::Browser.new :firefox, :profile => profile

Still the browser displaying download window when my script performs click operation on download button

Currently I'm using Firefox 35.0.1 on Windows-7(64bit)


回答1:


As per documentation, you should use the browser.helperApps.neverAsk.saveToDisk preference to achieve this. Value is defined as

A comma-separated list of MIME types to save to disk without asking what to use to open the file. Default value is an empty string.

I am not very good at Ruby, but it will probably look something like

profile["browser.helperApps.neverAsk.saveToDisk"] = "text/plain, application/octet-stream"

Just use the correct MIME type.


I also found this, this and this answer.



来源:https://stackoverflow.com/questions/30262889/how-to-disable-download-window-in-firefox-with-watir-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!