问题
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