Is there any method or
any way to get the name of browser using Web Driver?
public class JsExecute
{
WebDriver driver;
JavascriptExecutor js;
@Before
public void setUp()
throws Exception
{
driver=new
FirefoxDriver();
driver.get("http://www.google.com");
}
@Test
public void test()
{
JavascriptExecutor js
= (JavascriptExecutor) driver;
System.out.println(js.executeScript("return
navigator.appCodeName"));
}}
OR
String s = (String)
((JavascriptExecutor) driver).executeScript("return
navigator.userAgent;");
System.out.println("Browser
name : " + s);
Hi Ruchi,
ReplyDeleteThe above program is giving output as Mozilla for every browser..
Try this
System.setProperty("webdriver.chrome.driver", "C:\\webdriver\\Browser Drivers\\chromedriver.exe");
WebDriver wd=new ChromeDriver();
//WebDriver wd= new FirefoxDriver();
wd.get("http://www.google.com");
//JavascriptExecutor js=(JavascriptExecutor)wd;
//System.out.println(js.executeScript("return navigator.appName"));
Capabilities cap=((RemoteWebDriver) wd).getCapabilities();
String browsername=cap.getBrowserName();
String browserversion=cap.getVersion();
System.out.println(browsername+ " " +browserversion);
wd.close();
}
Thanks Madhu......Its Working......
Delete