如何避免 'This type of file can harm your computer' 使用 selenium 在 [=v11=] 自动化中弹出

How to avoid 'This type of file can harm your computer' pop up in chrome autoamtion using selenium

我正在使用 selenium 自动填写网站 chrome。当我下载 exe 或 XML 文件时,我得到一个带有保留和丢弃选项的弹出窗口 'This type of file can harm your computer'。如何以编程方式禁用此功能? 我在 c# 中实现这个, 我试过了,

chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true") 

但这对我不起作用。 如何禁用此弹出窗口? 如果不可能如何接受警告? 请帮助我。

可能你需要的是改变

chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true")     // disables blocking the popup

chromeOptions.AddUserProfilePreference("disable-popup-blocking", "false")   // enables blocking the popup

而不是为了避免弹出 window。

Edit :如果您遇到有害文件内容,您可以尝试设置一个 实验性 chrome 选项 使用:

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("safebrowsing.enabled", "true");
chromeOptions.setExperimentalOption("prefs", prefs);

引用文档 here 中的示例:

Set a Chrome preference

ChromeOptions options = new ChromeOptions(); 
Map<String, Object> prefs = new HashMap<String, Object>(); 
prefs.put("profile.default_content_settings.popups", 0);
options.setExperimentalOption("prefs", prefs);

日期 - 2016 年 6 月 4 日 [C#]

浏览了几个链接后发现 .Net 仍然没有 setExperimentalOption 首选项以及 ChromeOptions。因此,Add Argument to the ChromeOptions using C# with the flags listed here 的方法之一是:

chromeOptions.AddArgument("--safebrowsing-disable-download-protection");

Disables safebrowsing feature that checks download url and downloads content's hash to make sure the content are not malicious.

日期 - 2016 年 6 月 4 日 [JAVA]

文档here引用为:

public void setExperimentalOption(java.lang.String name, java.lang.Object value)

Sets an experimental option. Useful for new ChromeDriver options not yet exposed through the ChromeOptions API.

要禁用消息,您需要将首选项 safebrowsing.enabled 设置为 true。这是一个使用 CSharp 的工作示例:

var options = new ChromeOptions();
options.AddUserProfilePreference("download.default_directory", "C:\Downloads");
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("download.directory_upgrade", true);
options.AddUserProfilePreference("safebrowsing.enabled", true);

var driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("http://www.7-zip.org/a/7z1602.exe");

关于偏好的描述:

https://chromium.googlesource.com/chromium/src/+/master/chrome/common/pref_names.cc