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

0

7 Answers 7

1

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

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
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("")));
}
3
  • getCapabilities() is not a method on RemoteWebDriver Commented Apr 18, 2019 at 13:46
  • @NielsvanReijmersdal I stand corrected. The solution I provided is a Java solution, not C#.
    – hfontanez
    Commented Apr 19, 2019 at 19:12
  • The question is about C#, see topic/summary. This might be confusing :) Commented Apr 19, 2019 at 20:47
0
        IWebDriver driver = new ChromeDriver(AppPath);


        ICapabilities capabilities = ((ChromeDriver)driver). Capabilities;
        Console.WriteLine((capabilities.GetCapability("chrome") as Dictionary<string, object>)["chromedriverVersion"]);
0
public static string GetBrowserVersion() 
{ 
    string thisbrowserversion=""; 
    
    switch (ThisAppSettings.browserAppSetting.toLower())
    {
       case "chrome":
         thisbrowserversion = ((RemoteWebDriver)thisbrowser).Capabilities.GetCapability("version").ToString(); 
         break;
       case "firefox":
         thisbrowserversion = ((RemoteWebDriver)thisbrowser).Capabilities.GetCapability("browserVersion").ToString();
         break;
       default:
         // Throw exception stating unsupported browser

    }
    return thisbrowserversion; 
} 
1
  • Welcome to the community. Rather than just posting code, can you also explain how/why this is different or better than the accepted answer?
    – Lee Jensen
    Commented Mar 15, 2022 at 23:50
-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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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