1

I am testing with C# & Selenium & Selenium.Chrome.WebDriver (Nu-GET Package, Version 2.44.0). Now I am searching for a Method which gives me the actual Version of the current runnig driver.

Is there someone who can help me here I found this posts already but none of these helped: https://stackoverflow.com/questions/12556163/get-browser-version-using-selenium-webdriver https://mashtips.com/get-system-os-browser-version-java-selenium-webdriver/

enter image description here enter image description here

Thanks

1

If you are looking for the version of the ChromeDriver (this is different than the version of Chrome), it's a returned capability in chrome.chromedriverversion as a string.

0

Firefox and Chrome uses different string that you should use to get the versins, for Firefox is "browserVersion" and for Chrome is "version". browserCapabilities.GetCapability("browserVersion") - return the Firefox version, browserCapabilities.GetCapability("version") - return the Chrome version.You can make a method that check for the one or the second string and get the version of the browser.

0

((RemoteWebDriver) driver).getCapabilities().getVersion() should work for all browsers. I am not sure when this change took place, but when you examine the Capabilities class, it is obvious why this is the case:

default String getVersion() {
  return String.valueOf(Optional.ofNullable(getCapability("browserVersion")).orElse(
    Optional.ofNullable(getCapability("version")).orElse("")));
}
  • getCapabilities() is not a method on RemoteWebDriver – Niels van Reijmersdal Apr 18 at 13:46
  • @NielsvanReijmersdal I stand corrected. The solution I provided is a Java solution, not C#. – hfontanez Apr 19 at 19:12
  • The question is about C#, see topic/summary. This might be confusing :) – Niels van Reijmersdal Apr 19 at 20:47
0

If you want the actual version of the driver, e.g. the version of chromedriver.exe:

IWebDriver driver = new ChromeDriver("./");
ICapabilities capabilities = ((RemoteWebDriver)driver).Capabilities;
Console.WriteLine((capabilities.GetCapability("chrome") as Dictionary<string, object>)["chromedriverVersion"]);

This returns: 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72)

The capabilities object looks like this:

{
  "browserName": "chrome",
  "chrome": {
    "chromedriverVersion": "73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72)",
    "userDataDir": "C:\\Users\\NIELSV~1\\AppData\\Local\\Temp\\scoped_dir7524_3294"
  },
  "platform": "Windows NT",
  "version": "73.0.3683.103"
}

If you want to access deeper nested items you need to cast it to a Dictionary first.

-1

Thank you for your reply! Now I am using this workaround.

public static string GetBrowserVersion() 
{ 
    string thisbrowserversion; 
    if (ThisAppSettings.browserAppSetting == "Chrome") 
    { 
        thisbrowserversion = ((RemoteWebDriver)thisbrowser).Capabilities.GetCapability("version").ToString();     
    } 
    else 
    { 
        thisbrowserversion = ((RemoteWebDriver)thisbrowser).Capabilities.GetCapability("browserVersion").ToString(); 
    } 
    return thisbrowserversion; 
} 

Works fine. The Datatype "RemoteWebDriver" was the critical thing.

  • You don't need this workaround anymore. The Capabilities class already implemented this default behavior. – hfontanez Apr 2 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.