Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds
Asked Answered
W

21

114

I've been using Selenium for a number of months, which we're using to automate some of our internal testing processes. The scripts have been passing fine. I've recently upgraded to the C# 2.40.0 webdriver using FF 27.01 and our scripts are now failing in random places with the following error.

[Portal.SmokeTest.SmokeRunTest.Booking] TearDown method failed. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/element timed out after 60 seconds.
  ----> System.Net.WebException : The operation has timed out
TearDown : OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/window timed out after 60 seconds.
  ----> System.Net.WebException : The operation has timed out
[09:01:20]
[Portal.SmokeTest.SmokeRunTest.Booking] TearDown method failed. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/element timed out after 60 seconds.
  ----> System.Net.WebException : The operation has timed out
TearDown : OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/window timed out after 60 seconds.
  ----> System.Net.WebException : The operation has timed out
   at OpenQA.Selenium.Support.UI.DefaultWait`1.PropagateExceptionIfNotIgnored(Exception e)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
   at Portal.Test.Helpers.Process_Bookings.OpenBookings.SelectBooking(String bookingnumber)
   at Portal.SmokeTest.SmokeRunTest.Booking() in d:\TeamCityAgent\work\dac1dcea7f2e80df\SmokeTests\SmokeRunTest.cs:line 68
--WebException
   at System.Net.HttpWebRequest.GetResponse()
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
--TearDown
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
   at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Execute(Command commandToExecute)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Close()
   at Portal.Test.Helpers.Setup.CloseWebdriver()
   at Portal.SmokeTest.SmokeRunTest.TearDown() in d:\TeamCityAgent\work\dac1dcea7f2e80df\SmokeTests\SmokeRunTest.cs:line 162
--WebException
   at System.Net.HttpWebRequest.GetResponse()
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)

The latest error I've managed to track down to one single line of code:

_setup.driver.FindElement(By.XPath("//button[@class='buttonSmall lockBookingButton']")).Click();

The annoying thing is, trying to fix the problem is proving difficult, as if I run the test on my local machine, in debug it passes. Additionally, if I run it via the NUNIT runner on the build machine I'm running the test off, it also passes. It only seems to fail as part of our automated build running process when using Teamcity. Like I said, this has been running fine for months previously, and the only thing that has changed is the selenium webdriver kit.

I have experienced this problem before, whilst in debug, and when a Click() line of code was called, Firefox appeared to lock up, and only stopping the test would allow Firefox to continue. There are a number of suggestions on here including modifying the webdriver source? I'd like to not go down that route if possible if anyone else can offer any suggestions.

Woven answered 11/3, 2014 at 10:13 Comment(1)
We had exactly the same issue in several independent projects using this setup and have still no workaround for this. Our best bet was to downgrade to older versions of the WebDriver and Firefox assemblies. We also do not know whether this behavior is caused by WebDriver or Firefox.Cart
T
40

I had a similar issue using the Chrome driver (v2.23) / running the tests thru TeamCity. I was able to fix the issue by adding the "no-sandbox" flag to the Chrome options:

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

I'm not sure if there is a similar option for the FF driver. From what I understand the issue has something to do with TeamCity running Selenium under the SYSTEM account.

Tremolite answered 2/9, 2016 at 19:57 Comment(5)
this solve my problem as well. I was unable to run chrome tests anymore after months of not trying them. Thanks combatc2Amateur
My code was running fine in an IIS hosted env and stopped suddenly, but still worked in my unit tests. Adding this line made it work again in IIS env. Thanks!Gas
I delcared it as var options = new ChromeOptions(); options.AddArgument("--no-sandbox"); Working now in C# version Webdriver 3.14.Euglena
var options = new ChromeOptions(); options.AddArgument("--no-sandbox"); worked for c#Blacking
In my case, this works on Windows and within a test environment that has basically the same setup as production, but it won't work properly in production. Setting --remote-debugging-pipe and --no-sandbox solves other problems but not this one...Mcavoy
M
25
new FirefoxDriver(new FirefoxBinary(),new FirefoxProfile(),TimeSpan.FromSeconds(180));

Launch your browser using the above lines of code. It worked for me.

Mindful answered 8/5, 2015 at 4:22 Comment(1)
Fixed for us as well. When running a basic script which just created a FF driver and nothing else, a 60 second timeout worked 100% of the time. When running our resource-heavy script, which opens connections to databases/reads/writes/does a lot more immediately before opening FF, a 60 timeout would cause failures ~50% of the time. Increasing the timeout to 3 minutes fixed the problem. Seems that Webdriver just needs a little more time to get the engine warmed up.Tonietonight
P
21

I first encountered this issue months ago (also on the click() command), and it has been an issue for me ever since. It seems to be some sort of problem with the .NET Selenium bindings. This blog post by the guy that works on the IE driver is helpful in explaining what's happening:

http://jimevansmusic.blogspot.com/2012/11/net-bindings-whaddaymean-no-response.html

Unfortunately, there doesn't seem to be a real solution to this problem. Whenever this issue has been raised to the Selenium developers (see here), this is a typical response:

We need a reproducible scenario, that must include a sample page or a link to a public site's page where the issue can be reproduced.

If you are able to submit a consistently reproducible test case, that could be very helpful in putting this bug to rest for good.

That said, perhaps you can try this workaround in the meantime. If the HTML button that you are trying to click() has an onclick attribute which contains Javascript, consider using a JavascriptExecutor to execute that code directly, rather than calling the click() command. I found that executing the onclick Javascript directly allows some of my tests to pass.

Privet answered 17/4, 2014 at 15:49 Comment(0)
M
20

I had the same issue with Firefox. I switched over to Chrome with options and all has been fine since.

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

ChromeDriver driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), options, TimeSpan.FromMinutes(3));
driver.Manage().Timeouts().PageLoad.Add(System.TimeSpan.FromSeconds(30));
Memo answered 5/11, 2019 at 0:50 Comment(2)
I'm likely mistaken here, but it seems the last line there will have no effect. PageLoad is a TimeSpan itself, and .Add on TimeSpan is a pure function, which doesn't modify PageLoad it simply returns a new TimeSpan which is being discarded.Forayer
Passing the TimeSpan in the constructor only fixed it for me. I got a Click timeout which listens to the commandTimeout.Sufficient
T
6

In my case none of the answers above solved my problem completely. I ended up using the (no-sandbox) mode, the connection with extended timeout period (driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability, TimeSpan.FromMinutes(3));) and the page load timeout (driver.Manage().Timeouts().PageLoad.Add(System.TimeSpan.FromSeconds(30));) so now my code looks like this:

    public IWebDriver GetRemoteChromeDriver(string downloadPath)
    {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.AddArguments(
            "start-maximized",
            "enable-automation",
            "--headless",
            "--no-sandbox", //this is the relevant other arguments came from solving other issues
            "--disable-infobars",
            "--disable-dev-shm-usage",
            "--disable-browser-side-navigation",
            "--disable-gpu",
            "--ignore-certificate-errors");
        capability = chromeOptions.ToCapabilities();

        SetRemoteWebDriver();
        SetImplicitlyWait();
        Thread.Sleep(TimeSpan.FromSeconds(2));
        return driver;
    }
    
    private void SetImplicitlyWait()
    {
        driver.Manage().Timeouts().PageLoad.Add(TimeSpan.FromSeconds(30));
    }


    private void SetRemoteWebDriver()
    {
        driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability, TimeSpan.FromMinutes(3));
    }

But as I mentioned none of the above method solved my problem, I was continuously get the error, and multiple chromedriver.exe and chrome.exe processses were active (~10 of the chromedriver and ~50 of chrome).

So somewhere I read that after disposing the driver I should wait a few seconds before starting the next test, so I added the following line to dispose method:

    driver?.Quit();
    driver?.Dispose();
    Thread.Sleep(3000);

With this sleep modification I have no longer get the timeout error and there is no unnecessarily opened chromedriver.exe and chrome.exe processses.

I hope I helped someone who struggles with this issue for that long as I did.

Ted answered 7/9, 2020 at 8:7 Comment(2)
Yes! I've been dealing with this issue for like 5 months, this worked! woohooooChingchinghai
Yeesh, this really should be a bug with Selenium since clearly the call to Quite() and Dispose() have not finished their responsibilities by the time the function call returns. Moreover, the amount of Sleep time required to fix the bug is not constant. Sometimes 3 seconds works, sometimes 30 seconds is not enough...Rohde
A
5

Got similar issue. Try to set more time in driver's constructor - add eg.

var timespan = TimeSpan.FromMinutes(3);

var driver = new FirefoxDriver(binary, profile, timeSpan);
Arlinda answered 11/3, 2014 at 11:11 Comment(3)
Hi there bewu, would that be in the format like the below? driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));Woven
No, not this wait ImplicitlyWait is connected with finding elements. You need to change default(60sec) driver timeout, when it waits for request to be proceed(if I'm not wrong). Anyway you have to find a line where you set FF driver's constructor and add there more attributes or change the timeout. Something like: driver = new FirefoxDriver(new FirefoxBinary(), new FirefoxProfile(path to your profile), TimeSpan.FromMinutes(3));Arlinda
for ChromeDriver it would look like driver = new ChromeDriver(service, chromeDriverOptions, TimeSpan.FromMinutes(3));Ariminum
R
5

In my case, my button's type is submit not button and I change the Click to Sumbit then every work good. Something like below,

from driver.FindElement(By.Id("btnLogin")).Click();

to driver.FindElement(By.Id("btnLogin")).Submit();

BTW, I have been tried all the answer in this post but not work for me.

Roby answered 1/2, 2016 at 6:36 Comment(0)
I
4

In my case, it's because I deleted the chrome update folder. After chrome reinstall, it's working fine.

Improve answered 16/11, 2018 at 6:11 Comment(0)
C
2

I think this problem occurs when you try to access your web driver object after

1) a window has closed and you haven't yet switched to the parent

2) you switched to a window that wasn't quite ready and has been updated since you switched

waiting for the windowhandles.count to be what you're expecting doesn't take into account the page content nor does document.ready. I'm still searching for a solution to this problem

Caravette answered 29/2, 2016 at 10:17 Comment(0)
C
2

In my case I found this error happening in our teams build server. The tests worked on our local dev machines.

The problem was that the target website was not configured correctly on the build server, so it couldn't open the browser correctly.

We were using the chrome driver but I'm not sure that makes a difference.

Cariotta answered 11/11, 2016 at 15:43 Comment(0)
E
1

The problem is that the evaluation of Click() times out on your build env.. you might want to dig into what happens on Click().

Also, try adding Retrys for the Click() because occssionally the evaluations take longer time depending on network speeds, etc

Eddo answered 11/3, 2014 at 10:21 Comment(1)
Hi, The retry option wont work as the browser just locks up. Only stopping the test enables the browser to continue.Woven
M
1

In my case the issue was with SendKeys() and Remote Desktop. Posting the workaround I have so far:

I had a Selenium test which would fail when run as part of a Jenkins job on a node hosted in vSphere and administered through RDP. After some troubleshooting it turned out it succeeds if Remote Desktop is connected and focused but fails with the exception if Remote Desktop is disconnected or even minimized.

As a workaround, I logged through vSphere Console instead of RDP and then even after closing vSphere the test didn't fail anymore. This is a workaround but I would have to be careful never to login through RDP and always to administer only through vSphere Console.

Mcintire answered 10/4, 2019 at 14:43 Comment(0)
A
1

We had the same problem. In our case, the browser was blocked by a login popup (Windows authentication), so not returning after 60 seconds. Adding correct access rights to the Windows account Chrome was running under solved the problem.

Appoint answered 12/7, 2019 at 5:26 Comment(0)
P
1

I had the same exception when trying to run a headless ChromeDriver with a scheduled task on a windows server (unattended). What solved it for me is to run the task as the user "Administrators" (notice the S at the end). What I also did (I don't know if its relevant) is selected the "Any Connection" from the task "Conditions" tab.

Pay answered 7/10, 2020 at 8:46 Comment(0)
L
1

I was getting this issue. I'd neglected to update the Selenium.WebDriver.ChromeDriver nuget package to match the version of Chrome I was using. Once I did that the issue was resolved. enter image description here

Lamori answered 18/1, 2022 at 10:22 Comment(2)
I just had this problem. Typically when a new version releases my tests will just outright fail and won't run because of an incompatible version but apparently running Chrome 101 with ChromeDriver 100 works but gave those errors intermittently. Such a silly mistake.Ionosphere
Aaand I was wrong. Still get that error after updating.Ionosphere
E
0

changing the Selenium.WebDriver.ChromeDriver from 2.40.0 to 2.27.0 is ok for me

Ebracteate answered 19/6, 2018 at 7:27 Comment(0)
C
0

The new FirefoxDriver(binary, profile, timeSpan) has been obsolete.

You can now use new FirefoxDriver(FirefoxDriverService.CreateDefaultService(), FirefoxOptions options, TimeSpan commandTimeout) instead.

There is also a new FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options, TimeSpan commandTimeout) and it does works. But it's undocumented, and you need to manually specify geckoDriverDirectory even though it's already in Path.

Chronoscope answered 30/5, 2019 at 5:36 Comment(0)
E
0

Arrrgh! Faced this on macOS today and the issue was as simple as - the pop-up window suggesting to install the new Appium version was showing on the remote CI build server.

Just VNC'ing to it and clicking "Install later" fixed it.

Essential answered 8/10, 2019 at 17:29 Comment(0)
P
0

I see this issue as well when running my tests so have been searching for the 'why' and the 'how to fix'.

My initial thought (after looking at the screenshot failures and the timeout message) was that the website performance must have gotten worse and that the website is taking longer to do some stuff which is causing the issue.

I've found a lot of solutions (which I plan to try out) HOWEVER, it seems like Most of the solution sort of indicate that the website performance (reaction time) got slower. If you have to change wait for 30 seconds to wait for 3 minutes, it is true that this will allow the test to pass ... but doesn't this mean we are having to wait around 3 minutes for the website to do something?

Question: Can 90% of the time this error message be chalked up to degradation of the website performance? I read some sites mentioned above and it sounds like the issue could also be with the chromedriver causing delays (maybe nothing to do with application issues). Is anyone brining this issue up to their application development team or are you just changing the wait times and not reporting?

Penalty answered 9/4, 2021 at 20:39 Comment(0)
F
0

I posted in selenium slack channel on how the timeout that we pass for Chromedriver constructor works and got this answer(C#). "The timeout that you can set in the driver constructor is the 'command timeout' which is essentially the read timeout for the http client. The http client knows nothing about what the driver is doing.

If the page never loads and the command timeout is less than the page load timeout, you'll get an error saying "HTTP request to the remote WebDriver server timed out".

If the command timeout is greater than the page load timeout, the driver will respond to the client with a timeout error, and Selenium will report the message received by the driver."

Floweret answered 13/1, 2023 at 4:50 Comment(0)
G
-2

For ChromeDriver the below worked for me:

string chromeDriverDirectory = "C:\\temp\\2.37";
 var options = new ChromeOptions();
 options.AddArgument("-no-sandbox");
 driver = new ChromeDriver(chromeDriverDirectory, options, 
 TimeSpan.FromMinutes(2));

Selenium version 3.11, ChromeDriver 2.37

Gradient answered 19/3, 2018 at 17:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.