通过Options类或DesiredCapabilities禁用IE弹出窗口阻止程序

时间:2015-03-27 17:40:21

标签: c# internet-explorer selenium selenium-webdriver webdriver

我知道这可以通过转到工具>互联网选项>隐私并取消选中启用弹出式窗口拦截器来手动完成。问题是如果我在另一台机器上运行这些测试,那么与弹出窗口相关的测试将会失败。有没有办法使用OptionsDesireCapabilitiesInternet Explorer完成此操作。我尝试过选项

var options = new InternetExplorerOptions { EnableNativeEvents = false };
options.EnsureCleanSession = true;
options.UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Dismiss;

我试过了

InternetExplorerUnexpectedAlertBehavior.Accept;

但是,没有奏效。仍会阻止弹出

enter image description here

1 个答案:

答案 0 :(得分:2)

导入此 - Microsoft.Win32

RegistryKey regKey = default(RegistryKey);
regKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\New Windows", true);
regKey.SetValue("PopupMgr", 0);
regKey.Close();
相关问题