尽管将 safebrowsing.enabled
设置为 true
/false
,警告...这种类型的文件可能会损害您的计算机... 仍在浏览器中显示。如何隐藏这些信息?
最佳答案
启用使用 Chrome 下载文件/ChromeDriver隐藏警告此类文件可能会损害您的计算机,您需要:
- 添加首选项:
download.default_directory
download.prompt_for_download
download.extensions_to_open
safebrowsing.enabled
- 同时将以下参数添加到 whilelist 中:
--safebrowsing-disable-download-protection
安全浏览-禁用-扩展-黑名单
演示
使用 selenium-chromedriver 演示下载,和google-chrome通过java我点击了网页中的第一个下载
链接http://www.landxmlproject.org/file-cabinet您的有效解决方案将是:
代码块:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe"); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("download.default_directory", "C:/Utility/Downloads/"); prefs.put("download.prompt_for_download", false); prefs.put("download.extensions_to_open", "application/xml"); prefs.put("safebrowsing.enabled", true); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); options.addArguments("start-maximized"); options.addArguments("--safebrowsing-disable-download-protection"); options.addArguments("safebrowsing-disable-extension-blacklist"); WebDriver driver = new ChromeDriver(options); driver.get("http://www.landxmlproject.org/file-cabinet"); new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='MntnRoad.xml']//following::span[1]//a[text()='Download']"))).click();
浏览器快照:
关于java - 如何使用 Chrome Chromedriver 79 和 Selenium Java 下载 .xml 文件时隐藏警告 "This type of file can harm your computer",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59840198/