Do you have questions ? We got the answers!

Ask a question:

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

Open 1 Answers 32 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 (245 points)
edited Sep 1 by rajeevtechexpert

Top Contributors

  • 4970 pointsstbadmin

    34 questions 454 answers218 comments

  • 433 pointsSunilBhaskar

    41 questions 15 answers32 comments

  • 425 pointsMehedi

    36 questions 3 answers14 comments

  • 363 pointssumitkumarwatts

    0 questions 13 answers0 comments

  • 354 pointsSoft Tester

    43 questions 0 answers4 comments

  • 327 pointsKeeshaGolden

    0 questions 17 answers2 comments

  • 322 pointsVipul Sharma

    44 questions 0 answers24 comments

  • 310 pointsvysh.sharma

    25 questions 0 answers0 comments

  • 267 pointsOnkar_Nimje

    33 questions 15 answers15 comments

  • 258 pointsVanitha

    26 questions 0 answers6 comments

...