是否有任何方法强制webdriver/internetexplorerdriver在兼容模式下打开站点?每次我通过Nunit运行我的测试时,所有的历史和兼容性模式列表(我之前列出的站点在哪里)都会被清除。
我不能改变网站的代码。我可以添加项目到兼容性模式列表或打开网站的具体版本的IE (我有11,我需要在7打开它与文件类型5)。
发布于 2015-04-25 17:39:24
这是更好的描述我的问题:我需要测试一个网站,我不能编辑。该网站只工作在兼容模式在我的IE 11 (它是为ie 7文档类型5)。我想做测试,饼干应该在那之前清理干净。但是,如果我设置为"EnsureCleanSession = true“,那么除了cookie之外,它还会清除IE中的兼容列表。因为它,它是不可能测试的网站。
我已经找到了可能的解决方案,但我得测试一下.我发现兼容性列表在注册表中,我可以在清除它之前加载它的值,然后再次设置它的值:
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);
}发布于 2015-04-24 13:14:49
不幸的是,除非您更改了源代码,否则不会。作为解决办法,我使用VMS。如果您想使用相同的路由,请考虑使用使用Microsoft的免费VM。见我关于这里问题的另一个答案
https://stackoverflow.com/questions/29844094
复制相似问题