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

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.<GetExecutor>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.<InvokeActionAsyncCore>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.<ExecuteAsync>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.<SendAsync>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;
       }

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 53 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Adding this line, prevents the exception from happening:

co.AddArgument("no-sandbox");

Wonder how it worked before???

I am having the same issue but with Azure Dev Ops on a hosted agent.

same error here, happens when i update chromedriver: image

reset it back to 2.40.0 it works fine

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:<random port number>” URL is coming from), you’ll need to figure out how to allow that communication to take place.

Folks, the issues with Azure DevOps aren’t issues with Selenium. As such, I’m not sure this issue report is the correct forum for getting things resolved to your satisfaction.

It might be useful to review how WebDriver works under the hood. Remember that WebDriver communicates between the language bindings (or “local end,” in W3C spec parlance) and the browser driver (chromedriver.exe, or “remote end”) via HTTP on the localhost loopback adapter. This is normal and by design. This, incidentally, is why you see the “Only local connections are allowed” message output by chromedriver.exe.

It is possible in the language bindings to specifically set the port that chromedriver.exe listens on. In C#, this is done via the Port property of the ChromeDriverService class, and there is a constructor overload for ChromeDriver that takes an instance of this class.

Finally, if you’re using a NuGet package to retrieve the chromedriver.exe (or any other browser driver) binary, you should be aware that the Selenium project does not maintain those packages. We have no insight into the maintenance of them, nor of how they manage the binaries contained within.

As for what the exception message actually means, it means the same thing it’s meant since the driver was architected to use HTTP. There is a blog post that, while six years old at the time of this writing, still accurately describes what’s happening in the driver, and why you receive the error you do.

@Huffman17 I think you may be mistaken on several fronts. I’m well aware of the level of collaboration (or lack thereof) between the Selenium project and the maintainers of chromedriver.exe (the Google-sponsored Chromium project). The two projects are dependent on one another to be sure, but they share virtually no contributors between them. Moreover, as @barancev mentioned, the Chromium contributors do not routinely monitor the Selenium project’s issue tracker.

The comment about why HTTP is being used is, in fact, a direct response to a question posed in a comment in this issue. Specifically, where @Enielezi asked, “Can anyone please explain why http communication is requiring http://localhost server.”

I’ll be the first to admit that there are a number of things I do not know about; the workings of the .NET bindings (of which I’m the primary author), and the governance and maintenance of the Selenium project itself (of which I’ve been a core contributor for over eight years, and been a part of the project leadership committee for over two years) are not among those things. The implication that I am unclear on these details is simply incorrect, and frankly, insulting.

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

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.

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.

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.