selenium - internetexplorer 驱动程序兼容模式

selenium - internetexplorerdriver compatibility mode

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

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

很遗憾,不能,除非您更改源代码。作为解决方法,我使用 VMS。如果您想使用相同的路线,请考虑 using free VMs from Microsoft. See my another answer related to question

这是对我的问题的更好描述:我需要测试一个我无法编辑的网站。该站点仅在我的 IE 11 中以兼容模式工作(它是为 ie 7 doc type 5 制作的)。我想 运行 测试和饼干应在此之前清理。但是如果我设置 "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);
    }