Friday, June 7, 2013

Selenium 2 asks, What Browser are you?

Selenium 2 asks, "What Browser are you?"

If you have a test that is curious about what browser type or version is running it is possible to have it ask the browser what it is.

Perhaps the layout of the page changes or the content based on the version of the browser and different locators need to be built for different types or versions.

WebDriver driver = new InternetExplorerDriver();
String userAgent = (String) ((JavascriptExecutor)driver).executeScript("return navigator.userAgent;");

System.out.println(userAgent);

Now that you have the user agent, you need to interpret the user agent into the proper action.


© Copyright 2013 LMN Solutions
If you  have a question e-mail us or add a comment.


LMN Solutions - Find out more about us.
Selenium Training
selenium@lmnsolutions.com

No comments:

Post a Comment