How to get the Browser info in C# WebDriver?
Asked Answered
L

4

7

I see a ICapabilities interface to get the Browser info;Did couple of googling with no luck for any code example; Can anybody please share anything how I can get the browser info for a particular IWebDriver instance ? I am using C# webdriver.

Lindi answered 30/4, 2013 at 4:24 Comment(0)
C
15

In order to get info defined in ICapabilities interface, you need to cast IWebDriver instance to RemoteWebDriver. Then you can get the info about BrowserName, IsJavaScriptEnabled, Platform and Version.

IWebDriver driver = new FirefoxDriver();
ICapabilities capabilities = ((RemoteWebDriver)driver).Capabilities;

// then you have
// capabilities.BrowserName;
// capabilities.IsJavaScriptEnabled;
// capabilities.Platform;
// capabilities.Version;
Conservation answered 30/4, 2013 at 4:39 Comment(1)
For Internet Explorer, capabilities.Version only returns the major version (11). Do you know how to get the minor version of IE as well?Towrey
H
1

I use below code to get Chrome driver version

    IWebDriver driver = new ChromeDriver();
    
    ICapabilities capabilities = ((OpenQA.Selenium.WebDriver)driver).Capabilities;

    var SeleniumWebDriverName = driver.GetType().ToString();
    var SeleniumWebDriverVersion = (capabilities.GetCapability("chrome") as Dictionary<string, object>)["chromedriverVersion"];
    Console.WriteLine( "DRIVER NAME ====" + SeleniumWebDriverName );
    Console.WriteLine( "VERSION ====" + SeleniumWebDriverVersion + Environment.NewLine);
Heterochromatic answered 8/6, 2022 at 1:38 Comment(0)
D
0

Based on the old Yi Zeng answer, I was able to acces with the next code:

IWebDriver driver = new FirefoxDriver();
ICapabilities capabilities = ((WebDriver)driver).Capabilities;
    
// then you have
// capabilities.GetCapability("browserName");
// ...
Dinny answered 17/12, 2021 at 20:56 Comment(0)
C
-1

I've stumbled across an easier way if you just need to know which driver is running to get around a hack:

Driver.GetType().ToString();

Conway answered 25/9, 2014 at 21:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.