Microsoft Web 驱动程序已停止工作。在 Selenium 中使用 EdgeDriver 和 Microsoft Edge 导致程序停止正常工作的问题

Microsoft Web Driver has stopped working. A problem cause the program to stop working correctly error using EdgeDriver and Microsoft Edge in Selenium

如何在 Selenium 中 运行 Microsoft Edge。每次我 运行 测试时,Edge 浏览器都会打开但不会加载任何 URL。然后它会显示一个带有文本的小对话框:

Microsoft Web Driver has stopped working. A problem cause the program to stop working correctly. Please close the program

我正在使用:

代码试用:

using OpenQA.Selenium.Edge;
driver = new EdgeDriver();

这个错误信息...

Microsoft Web Driver has stopped working. A problem cause the program to stop working correctly. Please close the program

...意味着 MicrosoftWebDriver 无法 initiate/spawn 新的 浏览上下文 Microsoft Edge 浏览器 会话。


当您使用 Microsoft Edge Browser Version 18.17763 时,根据 Enhancing automated testing in Microsoft Edge with new WebDriver capabilities, W3C protocol support, and automatic updates, now MicrosoftWebDriver is a Windows Feature on Demand (FoD) 中的文档,确保它始终自动更新,并启用一些新的获取 Microsoft WebDriver 的方法。

步骤

  • 启用开发人员模式,这将安装适当版本的 WebDriver。

    Open Settings app > Go to Update & Security > For Developer and then select "Developer Mode".
    
  • 您还可以通过以下两种方式之一安装独立版本的 WebDriver:

    • 从“开始”搜索 "Manage optional features",然后 select "Add a Feature"、"WebDriver"。
    • 在提升的命令提示符中通过 运行 以下命令通过 DISM 安装:

      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.