2

Opening a browser (google chrome) in a different language through selenium WebDriver works fine when running on PC, as described here. But when trying it on linux based systems, or mac-os, it simply doesn't work, and the browser opens on it's default language. I tried using different language code, such as "es_ES" or "es-ES" instead of "es", but nothing helped. Is it a different language code for linux, or is it a different way to manipulate the web driver and not use the "--lang" command?

Thanks.

Amit Pe'er
  • 173
  • 1
  • 12

3 Answers3

0

I haven't try it but I think you can change the setting from chrome itself as :-

settings -> Lamguages -> Add languages.

Add your language there and give a try. remove other language if required.

For IE refer below link :-

http://www.reliply.org/info/internet/http-accept-lang.html

I have also found a code on same link you shared. Have you tried it?

DesiredCapabilities jsCapabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();
prefs.put("intl.accept_languages", language);
options.setExperimentalOption("prefs", prefs);
jsCapabilities.setCapability(ChromeOptions.CAPABILITY, options);

Source :-

Set Chrome's language using Selenium ChromeDriver

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • Changing through settings is problematic, since I need it to happen automatically - It runs on a remote machine. Regarding the second piece of code - I already tried it. it doesn't help. Browser still opens on English. – Amit Pe'er Aug 10 '17 at 14:15
  • Yes i can understand .. have you tried 2nd apporach by code – Shubham Jain Aug 10 '17 at 14:16
0

Maybe you also need to set prefs > intl > accept_language: en-GB

"desiredCapabilities": { "browserName": "chrome", "chromeOptions": { "args": ["--lang=en-GB"], "prefs": { "intl": { "accept_languages": "en-GB" } } } }

obotezat
  • 1,041
  • 16
  • 20
0

As you can read at developer.chrome.com, there is a system-dependand way to set language for Chrome. On Linux, a environment variable is required.

I created a Bash script like this:

#!/bin/sh

LANGUAGE="en" "/home/plap/projects/pdf-exporter/chromedriver" $*

Then I use the path of the script in the place of the path of the real chromedriver executable.

Moreover, since I need to swich language programmatically, I made code to save scripts like that programmatically at each new language required. Indeed the code calls:

System.setProperty("webdriver.chrome.driver", executableFile.getAbsolutePath());

in a synchronized block together with new ChromeDriver(options)... Yes, it's horrible!

Plap
  • 1,046
  • 1
  • 8
  • 14