OpenQA.Selenium.WebDriverException 实例化新的 EdgeDriver() 时

OpenQA.Selenium.WebDriverException when instantiating new EdgeDriver()

我有一组使用 Selenium 的 xunit 测试,所有 运行 适用于 Chrome 和 Internet Explorer。最近补充的是需要用Edge来测试。安装Selenium.WebDriver.MicrosoftDriver 17.17134.0后,遇到这个错误信息:

A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:{FOO}/session. The status of the exception was UnknownError, and the message was: An error occurred while sending the request. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..

Note: the port, represented above by {FOO} changes on each run, and not to any port configured anywhere in launchSettings.json files nor anywhere else in this solution.

运行ning测试时出现错误,在下面一行:

    IWebDriver result = new EdgeDriver();

您使用的是哪个版本的 Edge 浏览器?出现此错误主要是因为您使用的 Microsoft WebDriver 版本与您使用的 Edge 版本不匹配。

如果您使用的是 18 之前的 Edge Legacy 版本New Edge Chromium,您可以下载适合您安装的网络驱动程序this link. If your Edge Legacy version is 18 or higher, you can install the appropriate webdriver version according to the ways in this article.

中的 Microsoft Edge 版本

类似问题也可以参考