0

有什么方法可以强制 webdriver/internetexplorerdriver 以兼容模式打开站点。每次我通过 Nunit 运行测试时,都会清除所有历史记录和兼容模式列表(我的网站之前列出的位置)。

我无法更改网站的代码。我可以将项目添加到兼容模式列表或在特定版本的 IE 中打开站点(我有 11 个,我需要在 7 中使用 doc type 5 打开它)。

4

2 回答 2

0

不幸的是,没有,除非您更改源代码。作为一种解决方法,我使用 VMS。如果您想使用相同的路线,请考虑使用 Microsoft 的免费 VM在此处查看我与问题相关的另一个答案

于 2015-04-24T13:14:49.277 回答
0

这是对我的问题的更好描述:我需要测试一个我无法编辑的站点。该站点仅在我的 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);
    }
于 2015-04-25T17:39:24.800 回答