selenium icon indicating copy to clipboard operation
selenium copied to clipboard

The HTTP request to the remote WebDriver server for URL http://localhost:42607/session timed out after 60 seconds.

Open Legends opened this issue 8 years ago • 53 comments

Meta -

OS: Win 10 c64

Selenium Version: 3.9.0.0 Selenium.WebDriver.ChromeDriver version="2.35.0" targetFramework="net47"

Browser: Chrome Version 64.0.3282.140 (Official Build) (64-bit)

Expected Behavior -

Get data back. It is the same code I use in my unit test. My unit test passes successfully, but when running in IIS I get the error below.

Actual Behavior -

Throws exception when hitting the chromeDriver constructor. Strange exception message is: http://localhost:42607/session timed out after 60 seconds. I do not do a request to this url? I don't know where it comes from?! When I open this url in chrome, it displays: Unknown command.

{ "Message": "An error has occurred.", "ExceptionMessage": "The HTTP request to the remote WebDriver server for URL http://localhost:42607/session timed out after 60 seconds.", "ExceptionType": "OpenQA.Selenium.WebDriverException", "StackTrace": " at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)\r\n at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)\r\n at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)\r\n at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters)\r\n at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)\r\n at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)\r\n at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)\r\n at Web.Scraping.WebApi.ScrapeController.Post(List1 listDTO) in C:\Users\Admin\Documents\Visual Studio 2017\Projects\Phantomjs.UnitTests\Web.Scraping.WebApi\ScrapeController.cs:line 45\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()", "InnerException": { "Message": "An error has occurred.", "ExceptionMessage": "The request was aborted: The operation has timed out.", "ExceptionType": "System.Net.WebException", "StackTrace": " at System.Net.HttpWebRequest.GetResponse()\r\n at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)" } }

Steps to reproduce -

This code works fine in my unit test and also worked fine in IIS before, but out of sudden it is broken.

var co = new ChromeOptions();
           co.AddArgument("headless");
           co.AcceptInsecureCertificates = true;
           co.PageLoadStrategy = PageLoadStrategy.Normal;

           Dictionary<string, bool> dic = new Dictionary<string, bool>();

           using (var driver = new ChromeDriver(co))
           {
               try
               {
                   var urls = new string[] { paypalUrl, noPaypalUrl, paypalUrl1 };
                   driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

                   for (int i = 0; i < urls.Length; i++)
                   {
                       var url = urls[i];

                       var exists = driver.CheckElementExists(url, 
                           wt => !string.IsNullOrWhiteSpace(wt.FindElement(By.CssSelector("ul.payment-type-list")).Text), "li.pt-paypal");

                       dic.Add(url, exists);
                   }

                   driver.Close();

....

 static IWebElement TryFindElementByCssSelector(this ChromeDriver self, string cssSelector)
       {
           try
           {
               return self.FindElementByCssSelector(cssSelector);
           }
           catch (Exception) { }

           return null;
       }

       public static bool CheckElementExists(this ChromeDriver driver, string url, Func<IWebDriver, bool> waitCondition, string cssSelectorToLookFor)
       {
           driver.Navigate().GoToUrl(url);
           var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
           wait.Until(waitCondition);

           var liPaypal = driver.TryFindElementByCssSelector(cssSelectorToLookFor);

           return liPaypal == null ? false : true;
       }

Legends avatar Feb 07 '18 16:02 Legends

There's probably something about running in the context of an IIS process that's either preventing chromedriver.exe from launching or from receiving HTTP traffic from the language bindings. Since the language bindings (your C# code) uses HTTP to communicate with chromedriver.exe (that's where the "http://localhost:" URL is coming from), you'll need to figure out how to allow that communication to take place.

jimevans avatar Feb 07 '18 16:02 jimevans

It worked fine before, as I can remember, I have changed nothing.. I also cannot see anything in EventViewer. The exception is thrown during construction of ChromeDriver. I will analyze it further... DefaultAppPool and current user have full access to ChromeDriver.exe, so it is not related to security.

The question is: Where does this url "http://localhost:45157/session" from the exception message come from?

Legends avatar Feb 07 '18 16:02 Legends

Adding this line, prevents the exception from happening:

co.AddArgument("no-sandbox");

Wonder how it worked before???

Legends avatar Feb 07 '18 16:02 Legends

https://github.com/Googlechrome/puppeteer/issues/290#issuecomment-322882177

cgoldberg avatar Feb 07 '18 20:02 cgoldberg

Dangerous, yes, but EventViewer and the api itself don't provide me with usable information that I could analyze further. If you have any suggestions what further to check? The exe itself has full permissions! No Firewall issue. As I metnioned, it worked before...

Feel free to point me in any direction I should investigate in.

I have one mor question about correctly disposing ChromeDriver instance. I use Postman to execute a web api request, which then in turn creates a ChromeDriver instance in a using block. After the request has finished, ChromeDriver.exe is still active (Task manager)?? It should be disposed, even when an exception occurs, right?!

using (var driver = new ChromeDriver(co))
           {
               try
               {...

And where does this url "http://localhost:45157/session" from the exception message come from? I've hosted my web api in IIS and I have no binding on this port.


Windows detected your registry file is still in use by other applications or services. The file will be unloaded now. The applications or services that hold your registry file may not function properly afterwards. No user action is required.

DETAIL - 36 user registry handles leaked from \Registry\User\S-1-5-82-3006700770-424185619-1745488364-794895919-4004696415_Classes: Process 6276 (\Device\HarddiskVolume2\Users\Admin\Documents\Visual Studio 2017\Projects\UnitTests\Web.WebApi\bin\chromedriver.exe) has opened key \REGISTRY\USER\S-1-5-82-3006700770-424185619-1745488364-794895919-4004696415_Classes\Local Settings\Software\Microsoft

Legends avatar Feb 07 '18 22:02 Legends

Once again, the language bindings (your C# code) use HTTP to communicate with the browser driver (chromedriver.exe, geckodriver.exe, IEDriverServer.exe, etc.). It initiates a session with the driver by sending a POST to http://localhost:(some port value)/session. The WebDriver wire protocol is JSON-over-HTTP, so every command issues an HTTP call to localhost.

As for why sessions aren’t being created, I do not know. It’s unlikely that the Selenium project will be able to narrow down what the issue is. I’m certain it’s entirely dependent on the environment, being run under IIS. Beyond that, I do not have the ability or environment to narrow it down further.

jimevans avatar Feb 08 '18 01:02 jimevans

Thanks for your reply, I will consult with the ChromeDriver guys, perhaps they know what the issue is...

Legends avatar Feb 08 '18 16:02 Legends

Hi Team I am getting this issue again while running my scripts against chrome. I am using the latest version of Selenium & Chrome Driver.

image

Joothi avatar Jun 06 '18 11:06 Joothi

We had this issue using Selenium in a windows service. I found a resident console app living with the credential of the service's credential. I shut down our service, ended that task (i.e this console app linked to selenium) and made sure no Firefox instances (i.e. yup, we use Firefox) were not running and then started our service back up again. Everything worked as before. You may want to check your running tasks. Otherwise, if possible, restart the server your running your code on. Bottom line, there something resident causing it to happen, or at least, that was our issue. Hope this may help.

PMSIInterview avatar Jun 21 '18 23:06 PMSIInterview

I am facing the same issue. I tried updating Chrome, ChromeDriver and Selenium Nuget Package to the latest. Still the same failure The error is below The HTTP request to the remote WebDriver server for URL http://localhost:57322/session/1f6d9bf08336f880804a69bff68f15fc/element/0.798790339877028-9/value timed out after 60 seconds.

jacobjithin avatar Jun 25 '18 18:06 jacobjithin

I am facing the same issue. I can add more info: that error occurs when Chrome is already opened on my computer and I am running chromeDriver with Profile from "%appData\Local\Google\Chrome\User Data\Some profile" But if Chrome is closed (and all the processes are killed) and I am running chromeDriver with that Profile - this error doesn't occur. Selenium Version: 3.13.0.0 Selenium.WebDriver.ChromeDriver version="2.40" targetFramework="net47"

Browser: Chrome Version 67.0.3396.99 (Official Build) (64-bit)

AlexTesterSB avatar Jun 27 '18 11:06 AlexTesterSB

I am facing the same issue, Is there any updates on this one? I did notes that if I run my test local with VS 2017 it do past, but on 2015 still failing, can it be related?

DariaTl avatar Jul 15 '18 10:07 DariaTl

Hey Daria, I think one contributor mentioned a way to fix this issue for Chrome. Please see the responses from Legend above. The way I am able to fix this issue is to review running process on the server where selenium code is executing. You should see running processes that belong to your code. Then, just kill those processes. It requires a bit of review. If this happens a lot, you may need to look closer at the optional arguments. I wish I had more, but for us, I was able to identify and fix by killing the rouge processes. More of a support issue we see once in a great while. We use FireFox, and I have not tried the solution that Legend mentions. My thought is that it should work.

PMSIInterview avatar Jul 16 '18 15:07 PMSIInterview

thank you so much for your replay. I will try and see if its helps

On Mon, Jul 16, 2018 at 6:04 PM PMSIInterview [email protected] wrote:

Hey Daria, I think one contributor mentioned a way to fix this issue for Chrome. Please see the responses from Legend above. The way I am able to fix this issue is to review running process on the server where selenium code is executing. You should see running processes that belong to your code. Then, just kill those processes. It requires a bit of review. If this happens a lot, you may need to look closer at the optional arguments. I wish I had more, but for us, I was able to identify and fix by killing the rouge processes. More of a support issue we see once in a great while. We use FireFox, and I have not tried the solution that Legend mentions. My thought is that it should work.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SeleniumHQ/selenium/issues/5457#issuecomment-405278200, or mute the thread https://github.com/notifications/unsubscribe-auth/AjLwZPh3n6B_cobn6NOMbmOIdL3t9WToks5uHKt3gaJpZM4R89NH .

DariaTl avatar Jul 17 '18 14:07 DariaTl

No one have a solution?

serdam55 avatar Aug 06 '18 11:08 serdam55

I'm still having this problem with headless chrome and I've tried everything including:

  • setting no-sandbox
  • changing TcpIp settings (expanding port range and reduce time between retries)
  • reviewing rogue processes
  • programmatically ending any active chrome or chromedriver processes between each test

blamay avatar Aug 08 '18 17:08 blamay

I'm still having this problem with headless chrome

please open a new issue and include failing code and a stacktrace

cgoldberg avatar Aug 09 '18 03:08 cgoldberg

Has a new issue been opened? Is someone trying to figure this out?

SCarlAdams avatar Aug 29 '18 12:08 SCarlAdams

I face the same issue. Failures are happening only in remote test runs. Tests go all pass in Local runs and in debug mode. However, on remote server as well, the failures are intermittent. The same builds with no changes is passing in the next immediate run. This is leaving my tests as flaky and uncertain. Have tried all the suggestions above and the falky failures still remain. Please post the solution if any for this. Thank you.

MythilyM avatar Sep 12 '18 01:09 MythilyM

I am experiencing similar issue with IEDriver (3.5.1.0 (64-bit)) when trying to get elements by name. I am opening a local HTML file to measure width and height of some texts. I have tried terminating all ie processes; didn't help.

Here is the exception org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: Read timed out t org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646) at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:443) at org.openqa.selenium.remote.RemoteWebDriver.findElementsByTagName(RemoteWebDriver.java:490) at org.openqa.selenium.By$ByTagName.findElements(By.java:327) at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:404)

and here is the some relevant information from Event viewer

_Windows detected your registry file is still in use by other applications or services. The file will be unloaded now. The applications or services that hold your registry file may not function properly afterwards. No user action is required. IEDriverServer.exe) has opened key \REGISTRY\USER_

ozkanozcan77 avatar Sep 12 '18 08:09 ozkanozcan77