Customize Chrome webdriver using selenium to save files without prompting to save or discard files when downloading

依然范特西╮ 提交于 2019-12-06 11:58:12

问题


I am trying to automate downloading files using selenium with chrome as my browser using chromedriver. When i try downloading exe files its prompting me "This type of file can harm your computer, Discard or save it". i want it to download anyway without any prompt.

I have looked into few solutions like below:

chromeOptions = webdriver.ChromeOptions()
prefs = {"browser.helperApps.alwaysAsk.force" :False,"browser.helperApps.neverAsk.saveToDisk" : "application/octet-stream"}
chromeOptions.add_experimental_option("prefs",prefs)    
browser = webdriver.Chrome(executable_path=//path//to//chrome_driver,   chrome_options=chromeOptions)    

But this didn't help it still throws up the prompt. Any help on this is greatly appreciated.

Thanks,


回答1:


From what I understand, there is no way to tell Chrome not to warn on potentially dangerous binary file downloads, see:

  • ChromeDriver has no way to accept dangerous downloads (Archived)
  • Add option to automatically accept dangerous downloads (Wontfix)

As the simplest workaround, you might want to approach the problem with Firefox:

Also there have been numerous requests from dev community to allow to disable this warning to be able to run automated tests in Chrome. At the moment this is the only reason we're running our automated tests in Firefox only. Really annoying.



来源:https://stackoverflow.com/questions/31565821/customize-chrome-webdriver-using-selenium-to-save-files-without-prompting-to-sav

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