SOLVED! HTTP request to the remote WebDriver server for URL http://localhost:52847/….. timed out after 60 seconds.

I can finally sleep again! Just kidding …

For a few weeks, when running Selenium tests in Teamcity, once in a while, I would see tests failing with the following exception:

The HTTP request to the remote WebDriver server for URL http://localhost:52847/session/a56bcb818246209e5d359626409731ac/element/13961238-cb66-437e-9154-1c150eebaf70/value timed out after 60 seconds.

stack trace: 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.SendKeys(String text)

This exception would happen sometimes when executing the SendKeys() method, other times when using Click() or Text() or Displayed(). Or any other IWebElement interface  method (C#).

I do not think that it was caused by the C# code because when running the same code locally, the exception would never happen.

It only happened when running the Selenium tests in Teamcity, on virtual machines hosted in Azure.

The Chrome driver was created in a very straightforward way:

 ChromeOptions options = new ChromeOptions();
 options.EnableMobileEmulation(deviceName);
 ChromeDriver drv = new ChromeDriver(options);

OK, what now?

My suspicion is that the exception is happening because

  • either the Teamcity agent (where the UI tests run) is very slow or
  • the site is slow

 

I have searched for a solution for days.

Some people suggested adding the no-sandbox option:

options.AddArgument("no-sandbox");

It did not help.

Others advised that this may be caused by conflicting versions of software (chrome driver, selenium, etc).

Or that the code is causing it and I should use explicit waits (already doing it) instead of implicit waits.

Or that drivers or browsers were not closed correctly.

Or that I should clean temporary files.

Or that Teamcity is causing it.

None of these really helped.

What helped was creating the Chrome driver differently and specifying a timeout for it.

Also, increasing the page load timeout as follows:

 ChromeOptions options = new ChromeOptions();
 options.EnableMobileEmulation(deviceName);
 options.AddArgument("no-sandbox");

 ChromeDriver drv = new ChromeDriver(ChromeDriverService.CreateDefaultService(), options, TimeSpan.FromMinutes(3));
 drv.Manage().Timeouts().PageLoad.Add(System.TimeSpan.FromSeconds(30));  

 

I can sleep again since doing this.

I still get this exception when running UI tests in Teamcity.

But with 95% reduced frequency.

And yes, I still believe that it is somehow related to the site being very slow, occasionally.

 

2 Comments

  1. Thanks. This worked for me. But have no idea about what we are doing in below line of code:
    new ChromeDriver(ChromeDriverService.CreateDefaultService(), options, TimeSpan.FromMinutes(3));

    Earlier I initialised webdriver normally: driver =new ChromeDriver(options);
    What is ChromeDriverService.CreateDefaultService() doing?
    and what role this timeout plays here? I mean when this comes into the picture?

    Like

    Reply

Leave a comment