Internet Explorer 保护模式设置和缩放级别

Internet Explorer Protective mode setting and Zoom levels

using System;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium;

namespace CSharpAutomationFramework.Tests
{
        public class BrowserSource
    {
        var options = new InternetExplorerOptions();
        options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
            public bool IgnoreZoomLevel { get; set; }
        public bool IntroduceInstabilityByIgnoringProtectedModeSettings { get; set; }

        InternetExplorerDriver protectivemode = new InternetExplorerDriver(options);
        InternetExplorerOptions options = new InternetExplorerOptions();
        options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
        InternetExplorerDriver zoom = new InternetExplorerDriver(zoomoptions);
        InternetExplorerOptions zoomoptions = new InternetExplorerOptions();
        options.IgnoreZoomLevel = true;

        static string[] Browsers = {
            "ie"
    };
    }
}

我正在尝试使用上面的代码忽略缩放级别和保护模式设置,而 运行 我的 selenium 脚本但是脚本在构建解决方案时显示错误。不确定我哪里错了。

在使用 Selenium 3.xIEDriverServer 3.xInternet Explorer 你不能忽略 缩放级别 保护模式 设置。

如果您查看 Required Configuration of Internet Explorer Driver,可以清楚地提到以下几点:

保护模式

在 Windows Vista 或 Windows 7 上的 Internet Explorer 7 或更高版本上,您必须将每个区域的 保护模式 设置设置为相同价值。该值可以打开或关闭,只要每个区域都相同即可。要设置保护模式设置,您必须从“工具”菜单中选择“Internet 选项”,然后单击安全选项卡。对于每个区域,在标记为 启用保护模式 .

的选项卡底部会有一个复选框

@JimEvans 在他的文章 You're Doing It Wrong: IE Protected Mode and WebDriver 中明确提到:

Using the capability doesn't solve the underlying problem though. If a Protected Mode boundary is crossed, very unexpected behavior including hangs, element location not working, and clicks not being propagated, could result. To help warn people of this potential problem, the capability was given big scary-sounding names like INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS in Java and IntroduceInstabilityByIgnoringProtectedModeSettings in .NET. We really thought that telling the user that using this setting would introduce potential badness in their code would discourage its use, but it turned out not to be so.

浏览器缩放级别

浏览器缩放级别必须设置为 100%,以便本机鼠标事件可以设置为正确的坐标。


解决方案

根据 Required Configuration of Internet Explorer Driver :

  • Set/Unset 将所有 区域 .
  • 保护模式 设置为相同级别
  • 浏览器缩放级别设置为100%