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.
How to get the Browser info in C# WebDriver?
Asked Answered
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;
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
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);
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");
// ...
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();
© 2022 - 2024 — McMap. All rights reserved.