2
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 脚本时使用上面的代码忽略缩放级别和保护模式设置,但脚本在构建解决方案时显示错误。不知道我哪里出错了。

4

1 回答 1

2

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

如果您查看Internet Explorer 驱动程序的所需配置,则清楚地提到了以下几点:

保护模式

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

保护模式设置

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

但是,使用该功能并不能解决根本问题。如果跨越保护模式边界,可能会导致非常意外的行为,包括挂起、元素位置不工作和点击不传播。为了帮助警告人们这个潜在的问题,该功能被赋予了听起来很吓人的名字,比如INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINSJava.NETIntroduceInstabilityByIgnoringProtectedModeSettings中。我们真的认为告诉用户使用此设置会在他们的代码中引入潜在的错误会阻止其使用,但事实并非如此。

浏览器缩放级别

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


解决方案

根据Internet Explorer 驱动程序必需配置

  • 将所有区域的保护模式设置/取消设置为相同级别。
  • 浏览器缩放级别设置为100%
于 2018-04-16T07:00:52.533 回答