Welcome to the Question and Answer site for Software Testing Professionals

You can get your queries resolved from Software Testing Professionals.

Ask a Question

Get answers and give answers to questions from other members.

View All Questions

Get votes and earn points to build your reputation in community.

View Hot Questions

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

Solved 1 Answers 44 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 Sep 1, 2017 by rajeevtechexpert (408 points)
selected Jan 5 by mayur

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.

We have resolved 1.2k+ Software Testing queries!

Software Testing Board Weekly update

We will send you handpicked questions that you would love to answer.

View previous campaigns.

Top Contributors

...