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

Open 1 Answers 12 Views
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

0

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 by rajeevtechexpert (161 points)
edited Sep 1 by rajeevtechexpert
...