【问题标题】:An unhandled exception of type SeleniumWebDriverException occurred in WebDriverdll A exception with a null response was thrown using EdgeDriverWebDriver dll 中发生 Selenium WebDriverException 类型的未处理异常使用 EdgeDriver 引发了具有空响应的异常
【发布时间】:2019-12-23 21:01:07
【问题描述】:

我在 C# 中将 Selenium 与 Edge 驱动程序一起使用,但是当我运行代码时,我收到以下错误。 使用 OpenQA.Selenium; 使用 OpenQA.Selenium.Edge;

class HomePageTests
{
    static void Main(string[] args)
    {
        {
            {
                IWebDriver AzimaHome = new EdgeDriver();
                AzimaHome.Navigate().GoToUrl("http:www.msn.com");

                IList<IWebElement> terms = AzimaHome.FindElements(By.TagName("a"));
                terms.First(element => element.Text == "").Click();
            }
        }
    }
}

抛出异常:

OpenQA SeleniumWebDriverException' in WebDriver.dll
An unhandled exception of type SeleniumWebDriverException' occurred in WebDriverdll
A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:52586/session. The status of the exception was Receive Failure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive.

顺便说一下,这是在 Visual Studio 2019 中:

_05.NoSuchElementException.exe' (CLR v4.0.30319: _05.NoSuchElementException.exe): Loaded 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Private Assemblies\Runtime\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[17312] _05.NoSuchElementException.exe' has exited with code -1 (0xffffffff).

有人可以帮忙吗?

【问题讨论】:

    标签: c# selenium selenium-webdriver microsoft-edge selenium-edgedriver


    【解决方案1】:

    此错误消息...

    OpenQA SeleniumWebDriverException' in WebDriver.dll
    An unhandled exception of type SeleniumWebDriverException' occurred in WebDriverdll
    A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:52586/session. The status of the exception was Receive Failure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive.
    

    ...暗示 EdgeDriver 无法启动/产生新的浏览上下文,即 Microsoft Edge Browser 会话。

    有关您的 Microsoft Edge 和 Microsoft EdgeHTML 的更多详细信息将有助于我们以更好的方式调试问题。但是,如果您使用 EdgeHTML 18 或 EdgeHTML 19,请按照 Microsoft WebDriver 中的文档:

    Microsoft WebDriver for Microsoft Edge (EdgeHTML) 版本 18 和 19 是一项 Windows 按需功能,可确保它始终自动保持最新状态,并支持一些获取 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
    

    tl;博士

    根据Microsoft Edge Developer Guide:

    EdgeHTML 18 包括从Windows 10 October 2018 Update(10/2018,内部版本 17763)开始在当前版本的 Microsoft Edge 平台中提供的以下新功能和更新功能。有关特定 Windows Insider 预览版本的更改,请参阅 Microsoft Edge Changelog 和 What's New in EdgeHTML。

    【讨论】:

    • 我已完成上述所有建议,但仍收到与上述相同的错误消息。
    【解决方案2】:

    您的大部分代码都是正确的,除了最后一行。我修改了一下,用下面的代码测试了一下,可以正常运行:

    using System.Collections.Generic;
    using System.Linq;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Edge;
    
    public class webdriver
    {
        static void Main(string[] args)
        {    
            IWebDriver AzimaHome = new EdgeDriver();
            AzimaHome.Navigate().GoToUrl("http:www.msn.com");
    
            IList<IWebElement> terms = AzimaHome.FindElements(By.TagName("a"));
            terms.First(element => element.Text == "msn").Click();
        }
    }
    

    我认为出现该错误主要是因为您使用的 Microsoft WebDriver 版本与您使用的 Microsoft Edge 版本不匹配。

    如果您使用的是 18 之前的 Microsoft Edge 版本,您可以在this link 中为您安装的 Microsoft Edge 版本下载相应的 Web 驱动程序。如果您的 Microsoft Edge 版本为18 或更高版本,您可以按照this article 中的方式安装相应的 webdriver 版本。

    【讨论】:

    • 非常接近 ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多