我正在尝试使用 selenium 和 chrome 作为我的浏览器使用 chromedriver 自动下载文件。当我尝试下载 exe 文件时提示我“这种类型的文件可能会损害您的计算机,请丢弃或保存它”。我希望它在没有任何提示的情况下下载。
我研究了如下几个解决方案:
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)
但这并没有帮助它仍然抛出提示。 非常感谢对此的任何帮助。
谢谢,
最佳答案
据我所知,没有办法告诉 Chrome
不要对有潜在危险的二进制文件下载发出警告,请参阅:
- ChromeDriver has no way to accept dangerous downloads (已存档)
- Add option to automatically accept dangerous downloads (Wonfix)
作为最简单的解决方法,您可能希望使用 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.
关于java - 使用selenium自定义Chrome webdriver保存文件下载时不提示保存或丢弃文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31565821/