MicrosoftWebDriver.exe 应预安装在提升的命令提示符中

MicrosoftWebDriver.exe should be pre-installed in an elevated command prompt

我的机器上安装了以下版本的 Microsoft Edge:

Microsoft Edge 44.18362.449.0
Microsoft EdgeHTML 18.18363

我正在尝试通过以下代码将 webdrivermanager 用于 运行 我在 Edge 上的自动化测试 (java+selenium):

WebDriverManager.edgedriver().setup();
            driver = new EdgeDriver();

但是,它报错如下:

WebDriverManagerException: MicrosoftWebDriver.exe should be pre-installed in an elevated command prompt executing: dism /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
  1. webdrivermanager 不应该为我下载并安装它吗?
  2. 我该如何解决这个问题?

这个错误信息...

WebDriverManagerException: MicrosoftWebDriver.exe should be pre-installed in an elevated command prompt executing: dism /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0

...意味着 WebDriverManager 将无法安装最新版本的 MicrosoftWebDriver 二进制文件到 initiate/spawn 一个新的 浏览上下文 Microsoft Edge 浏览器 会话。


根据 Microsoft WebDriver 中的文档使用 Microsoft EdgeHTML 18:

Microsoft WebDriver for Microsoft Edge (EdgeHTML) versions 18 and 19 is a Windows Feature on Demand which ensures that it’s always up to date automatically and enables some new ways to get Microsoft WebDriver.

步骤

要进行配置,您必须启用开发人员模式:

Go to Settings > Update and Security > For Developer and then select "Developer mode".

要通过提升的命令提示符安装 运行 Microsoft Edge 版本 18

DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0

注意:通过DISM命令安装MicrosoftWebDriver时,默认情况下webdriver安装在以下子目录中目录:

  • 64 位:

    C:\Windows\SysWOW64\MicrosoftWebDriver.exe
    
  • 32位:

    C:\Windows\System32\MicrosoftWebDriver.exe
    

tl;博士

根据Microsoft Edge Developer Guide

EdgeHTML 18 includes the following new and updated features shipped in the current release of the Microsoft Edge platform, as of the Windows 10 October 2018 Update (10/2018, Build 17763). For changes in specific Windows Insider Preview builds, see the Microsoft Edge Changelog and What's New in EdgeHTML.