Reputation: 91
How can I get current browser locale from WebDriver? There is the way to set locale, e.g.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", "en");
m_webDriver = new FirefoxDriver(profile);
But the problem is that it doesn't always work for some reason (not sure, but seems it doesn't work for Windows 8). So I need to run driver with the set preferences, get browser locale to make sure it works or not, and use appropriate locale for UI elements.
Upvotes: 2
Views: 1558
Reputation: 1713
You can execute the following JavaScript in WebDriver to get it correct:
var language = window.navigator.userLanguage || window.navigator.language;
Upvotes: 1