marifrahman
marifrahman

Reputation: 690

How to get the Browser info in C# WebDriver?

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.

Upvotes: 7

Views: 13341

Answers (4)

HO LI Pin
HO LI Pin

Reputation: 1681

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);

Upvotes: 1

David L&#243;pez
David L&#243;pez

Reputation: 364

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");
// ...

Upvotes: 0

DavidP
DavidP

Reputation: 9

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();

Upvotes: -1

Yi Zeng
Yi Zeng

Reputation: 32855

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;

Upvotes: 15

Related Questions