我正在为我们的Web应用程序运行自动测试。看似随机的,它会失去与 Web 驱动程序的连接,并在尝试单击站点上的元素时显示以下异常。
OpenQA.Selenium.WebDriverException: 'A exception with a null response was
thrown sending an HTTP request to the remote WebDriver server for URL
http://localhost:51838/session/0adcb677d8062f712728d3aeb011e63e/element/
743947cc-ce53-4d82-a020-3ac9d6a6e6af/click.
The status of the exception was KeepAliveFailure, and the message was:
The underlying connection was closed: A connection that was expected to
be kept alive was closed by the server.'
内部例外:
套接字异常:
An existing connection was forcibly closed by the remote host
IOException:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
网页异常:
<i>The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
错误堆栈跟踪:
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebElement.Click()
at OpenQA.Selenium.Remote.RemoteWebElement.Submit()
at ACT.Web.Ui.Tests.PageCommands.DefaultCommand.LoginToAzure(String azureLogin, String azurePassword) in C:Dataszypr002My DocumentsactACT.Web.Ui.TestsPageCommandsDefaultCommand.cs:line 43
at ACT.Web.Ui.Tests.StepDefinitions.LoginPageSteps.WhenILoginToActAs(String user) in C:Dataszypr002My DocumentsactACT.Web.Ui.TestsStepDefinitionsLoginPageSteps.cs:line 26
at ACT.Web.Ui.Tests.StepDefinitions.LoginPageSteps.GivenICanLoginToAct() in C:Dataszypr002My DocumentsactACT.Web.Ui.TestsStepDefinitionsLoginPageSteps.cs:line 17
at lambda_method(Closure , IContextManager )
我会尝试为您的ChromeOptions添加一些额外的设置,如下所示:
var options = new ChromeOptions();
options.AddArgument("--disable-impl-side-painting"); //To fix no such session exception which appears when running tests for a prolonged period
options.AddArgument("--disable-extensions");
options.AddArguments("disable-infobars");
options.AddArgument("--no-sandbox");
driver = new ChromeDriver(options);
具体来说,--no-sandbox
和--disable-impl-side-painting
可能有助于解决连接已关闭的问题。