这是对我的问题的更好描述:我需要测试一个我无法编辑的网站。该站点仅在我的 IE 11 的兼容模式下工作(它是为 ie 7 doc type 5 制作的)。我想运行测试,在此之前应该清理 cookie。但是,如果我设置“EnsureCleanSession = true”,它会清除 IE 中除 cookie 之外的兼容性列表。因此,无法测试该站点。
我找到了可能的解决方案,但我必须对其进行测试...我发现兼容性列表在注册表中,我可以在清理之前加载它的值并再次设置该值:
const string keyName = @"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData";
var a = Registry.GetValue(keyName, "UserFilter" , "Return this default if NoSuchName does not exist.");
// value of registry is removed
Registry.SetValue(keyName, "UserFilter", a);
Console.ReadLine();
但正如我所说,我不知道它是否会成功......
[更新]
好的,它适用于小的解决方法(因为在更改注册表后必须重新启动 IE)
[SetUp]
public void SetUp()
{
//read the compatibility mode list from registry
const string path = @"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData";
const string key = "UserFilter";
var regValue = Registry.GetValue(path, key, "Return this default if NoSuchName does not exist.");
//run IE driver with cleaning of cookies and history
var options = new InternetExplorerOptions
{
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
EnsureCleanSession = true
};
_driver = new InternetExplorerDriver(IeDriversPath, options);
//cloase IE
_driver.Quit();
_driver.Dispose();
//put the compatibility mode list back into registry
Registry.SetValue(path, key, regValue);
//run IE driver without cleaning of cookies and history
options.EnsureCleanSession = false;
_driver = new InternetExplorerDriver(IeDriversPath, options);
}