Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

0
How to change the language of the browser in Selenium WebDriver?

Solved 1 Answers 142 Views
0 1
I am using Selenium WebDriver to execute my code. I have a scenario where I need to change the language of the browser. Can you explain how to do that?

1 Answer

1
Best answer
1

Many times QA testing services need to update browser locale multiple times during the execution of automation suite. In such cases, it is required to set the browser locale in the scrips.

Below is the syntax you can use for Firefox Browser :

FirefoxProfile profile = new FirefoxProfile();

//setting the locale french : 'fr'

profile.setPreference("intl.accept_languages","fr");

driver = new FirefoxDriver(profile);

driver.get("http://www.google.com);

 

Below is the syntax you can use for Chrome Browser :

System.setProperty("webdriver.chrome.driver","D:/.../chromedriver.exe");

ChromeOptions options = new ChromeOptions();

options.addArguments("-lang= sl");

ChromeDriver driver = new ChromeDriver(options);

driver.get("http://www.google.com);

 

Here are few samples for different languages:

//options.AddArgument("--lang=es"); //espanol

//options.AddArgument("--lang=es-mx"); //espanol (Latinoamerica), espanol

//options.AddArgument("--lang=en-ca"); //english (UK), english (us), english

//options.AddArgument("--lang=en-au"); //english (UK), english (us), english

//options.AddArgument("--lang=en-nz"); //english (UK), english (us), english

//options.AddArgument("--lang=zh"); //english (us), english

//options.AddArgument("--lang=zh-tw"); //Chinese (Traditional Chinese), Chinese, english (us), english

//options.AddArgument("--lang=zh-hk"); //Chinese (Traditional Chinese), Chinese, english (us), english

//options.AddArgument("--lang=zh-cn"); //Chinese (Simplified Chinese), Chinese, english (us), english

options.AddArgument("--lang=fr"); //Francais (France), Francais, english (us), english

//options.AddArgument("--lang=fr-ca"); //Francais (France), Francais, english (us), english

//options.AddArgument("--lang=aus"); //Francais (France), Francais, english (us), english

 

For IE browser, we need to update the locale manually in the browser.

answered by (408 points)
selected by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...