Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
13.5k views
by The go-to Tester (222 points)
retagged by
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 like 0 dislike
by The go-to Tester (448 points)
selected by
 
Best answer

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.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...