2

I'm declaring my Selenium WebDriver reference like this:

var driver = new FirefoxDriver(service, 
    new FirefoxOptions { 
        BrowserExecutableLocation = "XXXX", 
        Profile = firefoxProfile, 
        UseLegacyImplementation = true }, 
    new TimeSpan(0, 1, 30)); 

It works great 99% of the time, however there are certain cases where I want to change the default "commandTimeout" to something other than 90 seconds. How do I do this without redefining the driver?

I've explored all the methods/properties of the following class and it doesn't seem changing any of them has any effect:

driver.Manage().Timeouts()

There also this post, but it's not related to the "commandTimeout". There's this, which doesn't really cover AFTER the driver is created. Most posts about Selenium timeouts are concerned with Implicit Wait's or various other timeouts, not the timeout value specified in the driver's declaration.

Community
  • 1
  • 1
David Rogers
  • 2,601
  • 4
  • 39
  • 84

1 Answers1

1

Why would you need to set the commandTimeout afterward? It is actually only a backup for when a driver does not respond anymore. It doesn't have anything to do with driving browsers themselves.

Looking into the selenium source code, you can see the commandTimeout parameter is passed into the RemoteWebdriver.ICommandExecutor field, which is private. This means, after initialization, it is not possible to access or change the command timeout anymore.

A very hacky, and certainly not recommended 'solution' for this could be to use reflection to access the property. This however is certainly not recommended, since it heavily depends on the driver you are using, and can therefore break at any moment.

If you need high timeouts occasionally, it is often better to set the commandTimeout to a high value, and manage the timeout using ImplicitWait & co.

AZWN
  • 158
  • 12
  • Could you give an example of using reflection(maybe on a Firefox driver) to do that? I realize it's not a good way to go about it, since that time I've found another way to address my original timeout issue. Still would be interesting to have a alternative method, if only for posterity... – David Rogers Jul 18 '18 at 21:37