无法使用带有 Java 的 Selenium WebDriver 打开 IE11 驱动程序实例

Unable to open IE11 driver instance using Selenium WebDriver with Java

    System.setProperty("webdriver.ie.driver","C:\Users\IEDriverServer_Win32_2.45.0\IEDriverServer.exe");
    
    WebDriver driver = new InternetExplorerDriver();
    
    driver.get("http://xxx");
    

执行以上代码时显示错误:

Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones.

Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 1.33 seconds

有人可以建议解决这个问题吗?

如果所有区域的保护模式设置不同或浏览器已缩放,则无法打开 IE 浏览器实例。

  1. 要解决此问题,打开 IE 浏览器 并转到 Internet 选项 windows.
  2. 单击安全选项卡并确保“Internet”、“Local Intranet'、'Trusted sites' 和'Restricted sites' 有'Enable 保护模式' 已选中或未选中所有选项。
  3. 应用并保存设置并重新运行测试代码。这应该 工作。

下面提供了解决方法,可以帮助您暂时解决问题。

DesiredCapabilities caps = DesiredCapabilities.internetExplorer();

caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);

WebDriver driver = new InternetExplorerDriver(caps); 

注意: 如果您没有更改 IE 设置的权限,请联系您的 IT 管理员以获得所需的权限更改完成。

  • 保护模式 是 Internet Explorer (IE) 安全 的重要一步,它有助于保护用户免受 运行宁 一个权限受限的 IE 进程。
  • 保护模式设置,就像 IE 的几乎所有其他设置一样,是 存储在 Windows 注册表中,并在浏览器打开时检查 实例化。
  • 驱动程序需要为无法设置这些 IE 的人提供解决方法 设置,因为他们的机器被过度锁定等 功能 引入了功能。
  • 它只是绕过了注册表检查。使用该功能不会 虽然解决了潜在的问题。
  • 意外挂起元素位置不起作用,以及点击未传播,可能结果。
  • 为了帮助警告人们注意这个潜在问题,该功能是 给出听起来很吓人的名字,比如 INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS.
  • 请您的 IT 支持人员进行更改,如果仍在使用 您正在冒着代码稳定性的风险。

如果您在代理后面没有访问权限来更改保护模式设置,请使用此功能

DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
        cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

这会引入一些脆弱性