I have developed some Selenium tests for an AngularJS website. These tests work fine using Chrome Driver and Firefox Driver. I am in the process of also adding the option to run these tests in Internet Explorer Driver. Most of the time the tests work in Internet Explorer too, but I have experienced the following exception over five times:
OpenQA.Selenium.WebDriverException: 'A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:53472/session/4a73e505-772d-4ef0-beeb-cc15e8b1e647/elements. 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.'
Inner Exception
WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
The first time this exception ocurred, the tests had been ongoing for several minutes; the second time, the tests had been running for over 3 hours and were near completion.
Possibly relevant information:
IE Version: 11.778.18362.0
Selenium Version: 3.141.0
Selenium IE Driver (32-bit) Version: 3.150.1
OS Build 18363.778
The IEDriver is initialised as follows:
InternetExplorerOptions options = new InternetExplorerOptions
{
EnsureCleanSession = true,
EnableNativeEvents = true
};
InternetExplorerDriverService driverService = InternetExplorerDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
IWebDriver webDriver = new InternetExplorerDriver(driverService, options);
The line of my code that usually causes the exception is:
ICollection<IWebElement> webElementsIncludingDisabled = searchContext
.FindElements(pageElement.By);
where searchContext
is the driver and the selector is a simple CssSelector.
The relevant part of the stacktrace is:
OpenQA.Selenium.WebDriverException
HResult=0x80131500
Message=A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:53472/session/4a73e505-772d-4ef0-beeb-cc15e8b1e647/elements. 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.
Source=WebDriver
StackTrace:
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.RemoteWebDriver.FindElements(String mechanism, String value)
One one occasion, a similar exception is instead caused by the line in my code:
webElement.SendKeys(toSend);
The relevant part of the stacktrace is then:
OpenQA.Selenium.WebDriverException
HResult=0x80131500
Message=A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:50818/session/72b73c2e-d7b2-4e2d-be83-54c343db4109/element/aef8dad2-4c50-41a1-aa36-34957765812a/value. 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.
Source=WebDriver
StackTrace:
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)
...
This exception was originally thrown at this call stack:
System.Net.Sockets.NetworkStream.Read(byte[], int, int)
Inner Exception 1:
WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
Inner Exception 2:
IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Inner Exception 3:
SocketException: An existing connection was forcibly closed by the remote host
What could be causing this issue?
Is there a way I can affect the Keep Alive timeout that the WebDriver server uses?
Is this related to the webDriver.Manage().Timeouts().PageLoad timeout (currently at its default)?
If I instead try to use the 64-bit version of IEDriver (version 3.141.59), I experience a different issue: selenium always does not appear to communicate with the browser after the initial page load. The line that actually throws the exception in my code is
WebDriver.Url = expectedURL;
though, through observation, two attempts to SendKeys and a Click have already been unsuccessful by this point.
The relevant part of the stacktrace is:
OpenQA.Selenium.WebDriverException
HResult=0x80131500
Message=The HTTP request to the remote WebDriver server for URL http://localhost:55918/session/988d31c6-feb8-4cf0-8335-7c9eaecef6d1/url timed out after 60 seconds.
Source=WebDriver
StackTrace:
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) ...
This exception was originally thrown at this call stack:
System.Net.HttpWebRequest.GetResponse()
OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(OpenQA.Selenium.Remote.HttpCommandExecutor.HttpRequestInfo)
Inner Exception 1: WebException: The request was aborted: The operation has timed out.
I believe this 64 bit version problem is the same issue as Selenium IE driver hangs after navigating to URL