Selenium Error - the Http Request to the Remote Webdriver Timed Out After 60 Seconds

Selenium ChromeDriver - the HTTP request to the remote WebDriver server for URL timed out after 60 seconds

You need to increase the DefaultCommandTimeout in RemoteWebDriver. You can do it by using the ChromeDriver(ChromeDriverService, ChromeOptions, TimeSpan) or ChromeDriver(string, ChromeOptions, TimeSpan) overloads

ChromeOptions co = new ChromeOptions{};

Driver = new ChromeDriver("path to ChromeDriver.exe", co, TimeSpan.FromSeconds(120));
// or
Driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), co, TimeSpan.FromSeconds(120));

How to reproduce the Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds

You could try to add a web page which includes a button control, in the button click event, you can call a web API to get data. In the web API method, add Thread. Sleep () method to stop the executing thread for a given amount of time (more than the request time). Then, if you trigger the button click event using Selenium WebDriver, it will show this error.

Code like this:

Code in mvc view:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script>
$(function () {
$("#buttonSearchPro").click(function () {
$.ajax({
url: "@Url.Action("GetData", "Home")",
async: false,
success: function (data) {
alert(data);
}
});;
});
});
</script>
<input type="button" id="buttonSearchPro" class="btn btnAction" value="Download" />

Code in MVC controller:

    public ActionResult GetData()
{
Thread.Sleep(70000000);
return Json("OK", JsonRequestBehavior.AllowGet);
}

Code in console application:

    private const string URL = @"http://localhost:65330/Home/Index";
private const string IE_DRIVER_PATH = @"D:\Downloads\webdriver\IEDriverServer_x64_3.14.0";
static void Main(string[] args)
{

//EdgeWebDriver();
InternetExplorerTest();
}

public static void InternetExplorerTest()
{
try{

var options = new InternetExplorerOptions()
{
InitialBrowserUrl = URL,
IntroduceInstabilityByIgnoringProtectedModeSettings = true
};
var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);
driver.Navigate();
//find the button and trigger click event.
driver.FindElementById("buttonSearchPro").Click() ;
driver.Close(); // closes browser
driver.Quit(); // closes IEDriverServer process

}
catch (Exception e)
{
Console.WriteLine(e.Message);
}

Console.WriteLine("OK");
Console.ReadKey();
}

the result like this:

Sample Image

The HTTP request to the remote WebDriver server for URL ... timed out after 60 seconds

I have created some generic retry methods. This is a hack around a limitation in Selenium. Selenium has some built-in timeouts that can and should be used where appropriate, however not all calls to the drivers seem to honor those timeouts. Also, not all driver communication issues are a result of Selenium timing itself out after not hearing back; if the issue is due to network or permission issues then these methods will not help at all.

The main timeouts in Selenium for PageLoad, Script, and ImplicitWait should be used to fix timeout issues specific to those areas.

These methods (modified from another source) fix a very narrow set of issues where Selenium loses connection to the web driver part way through the call, or when it times out and you have no other way of extending the timeout period. They work by initiating a new call to the driver, in some instances this can result in the action being called multiple times in the browser, so use them with care.

    /// <summary>
/// These retry methods are necessary because Selenium is incapable of handling timeouts
/// inside it's own system when it temporarily loses connection to the Driver.
/// Called like:
/// var return = RetryWebDriverServiceCall(f => object.method(param));
/// var return = RetryWebDriverServiceCall(f => object.attribute);
/// </summary>
/// <param name="serviceMethod"></param>
public delegate void VoidAction(params object[] oArgs);
public void RetryWebDriverServiceCall(VoidAction serviceMethod)
{
for (var loop = 0; loop < 3; loop++)
{
try
{
serviceMethod();
break;
}
catch (WebDriverException ex) // (WebDriverTimeoutException ex)
{
if (!ex.Message.Contains("timed out after 60 seconds") || loop >= 2)
throw new Exception($"UI Retry #: {loop}", ex);
System.Threading.Thread.Sleep(500);
}
}
}

public delegate T ParamsAction<T>(params object[] oArgs);
public T RetryWebDriverServiceCall<T>(ParamsAction<T> serviceMethod)
{
for (var loop = 0; loop < 3; loop++)
{
try
{
return serviceMethod();
}
catch (WebDriverException ex)
{
if (!ex.Message.Contains("timed out after 60 seconds") || loop >= 2)
throw new Exception($"UI Retry #: {loop}", ex);
}
}

throw new Exception("RetryWebDriverServiceCall failed");
}

C# selenium HTTP request to the remote web driver server for URL timed out after 60 seconds

Use the Chrome in the standalone package that you downloaded instead of your system installation.You can do this by:

ChromeOptions options = new ChromeOptions();
options.BinaryLocation = @"path\\to\\the\\standalone\\chrome.exe";
// chrome installation exe

for : more



Related Topics



Leave a reply



Submit