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

标签 c# selenium selenium-webdriver selenium-iedriver iedriverserver

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 ConfigurationInternet Explorer Driver明确提到了以下几点:

保护模式

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

ProtectedModeSettings

@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%,以便 native 鼠标事件可以设置为正确的坐标。


解决方案

根据 Required ConfigurationInternet Explorer Driver :

  • 将所有区域保护模式设置设置为同一级别。
  • 浏览器缩放级别设置为100%

关于c# - Internet Explorer 保护模式设置和缩放级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49850465/

相关文章:

c# - 组合单词并从多个文本框生成变体

python - 使用try/except然后在类中抛出一个方法

python - 尝试使用 Selenium webdriver 登录时出错

java - 如何找到在selenium web驱动程序java中显式等待条件为真所花费的时间

C#:如何控制组合框中显示的当前项目索引?

c# - 以 Xamarin 形式提供隔离进程的后台服务

java - 如何到达appium中滚动条的末尾?

java - 如何使用 Selenium 和 Java 识别 <a> 中的文本

javascript - Protractor - 启动 chrome 以禁用 cors 的网络安全

C# 不使用对话框保存图像