Disable IE pop up blocker through Options class or

2019-05-23 15:17发布

问题:

I know this can be done manually once by going to Tools>Internet Options>Privacy and unchecking Turn on Pop-up Blocker. The problem is if I run these tests on a different machine the tests related to pop up window will fail. Is there a way to accomplish this using Options or DesireCapabilities for Internet Explorer. I have tried with options

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

I have tried

InternetExplorerUnexpectedAlertBehavior.Accept;

But, did not work. Still blocks the pop up

回答1:

Import this - Microsoft.Win32

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