c# - 必须为所有区域将启用保护模式设置为相同的值(启用或禁用)

标签 c# internet-explorer selenium

我正在尝试使用 Selenium Internet Explorer 驱动程序,但是当我尝试实例化它时它出现故障:

[TestInitialize]
public void TestInitialise() {
  ieDriver = new InternetExplorerDriver();
}

错误如下:

Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (NoSuchDriver).

我找到了解决我的问题的明显方法 here ,这建议设置驱动程序的 DesiredCapabilities,如图所示:

var capabilitiesInternet = new OpenQA.Selenium.Remote.DesiredCapabilities();
capabilitiesInternet.SetCapability("ignoreProtectedModeSettings", true);
IWebDriver webDriver = new InternetExplorerDriver(capabilitiesInternet);

唯一的问题是,我使用的是我能找到的最新版本的驱动程序,并且没有覆盖以 DesiredCapabilities 作为参数的 InternetExplorerDriver

现在是否有一些新的或其他方式来设置 DesiredCapabilites 而不是我使用的示例?

最佳答案

该设置可以解决该问题,但会引入一些微妙的问题。你是不是没有正确设置IE的保护模式?这是正确的解决方案。

指南在这里:

https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

基本上只是在 IE 中为每个区域关闭保护模式。

或者,如果您真的必须使用覆盖功能,那么您可以做两件事:

使用 InternetExplorerOptions 类。请注意该属性的名称,它会给您一个很大的线索,表明使用它不是一个好主意。

var options = new InternetExplorerOptions;
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
var driver = new InternetEplorerDriver(options);

或者使用 RemoteWebDriver,它可以接受 ICapabilities 接口(interface)的任何实现,DesiredCapabilites 实现了:

var capabilities = new DesiredCapabilities("internet explorer", string.Empty, new Platform(PlatformType.Windows));
capabilities.SetCapability("ignoreProtectedModeSettings", true);
var webDriver = new RemoteWebDriver(capabilities);

关于c# - 必须为所有区域将启用保护模式设置为相同的值(启用或禁用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13383773/

相关文章:

c# - 类型参数声明必须是标识符而不是类型

Jquery 自动完成滚动条未出现在 IE 中

javascript - ExtJS 和 Internet Explorer : Layout corruption with scrollbars

excel - 如何使用 Selenium VBA 获取 innerHTML

c# - EWS 订阅收件箱中的流式通知

c# - Asp.Net Core 2.1 ApiController 不会自动验证单元测试下的模型

html - CSS-垂直对齐属性不起作用

python - 无效参数异常 : Message: invalid argument: user data directory is already in use error while initiating Chrome with ChromeDriver Selenium

javascript - 如何在 Selenium WebDriver 中使用 JavascriptExecuter 设置属性值

c# - 为什么我所有的 log4net 级别都是错误的?