【问题标题】:selenium - internetexplorerdriver compatibility modeselenium - internetexplorerdriver 兼容模式
【发布时间】:2015-04-24 09:43:34
【问题描述】:

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

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

【问题讨论】:

    标签: c# selenium webdriver nunit compatibility-mode


    【解决方案1】:

    很遗憾,没有,除非您更改源代码。作为一种解决方法,我使用 VMS。如果您想使用相同的路线,请考虑using free VMs from Microsoft。请参阅我与问题here相关的另一个答案

    【讨论】:

    • 我已将您之前的答案标记为红色,您参考了另一个答案:stackoverflow.com/questions/5804714/…。我想向自己保证,除了虚拟机之外别无选择。更具体地说,我对清除兼容性列表的“EnsureCleanSession = true”有疑问。如果他不这样做,对我来说一切都会好起来的:/
    • 您有什么问题?饼干?
    【解决方案2】:

    这是对我的问题的更好描述:我需要测试一个我无法编辑的网站。该站点仅在我的 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);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-09
      • 2017-03-04
      • 1970-01-01
      • 1970-01-01
      • 2014-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多