0

It does not work chrome browser language setting as below using selenium + Java. Can someone help on this to find reson behind that ?

ChromeOptions optionsChrome = new ChromeOptions();
optionsChrome.addArguments("--lang=ja");
driver = new ChromeDriver(optionsChrome);
Primal
  • 33
  • 2
  • 4
  • Below code is working for this issue. But still I have question above asked . I need to know why this is happening ChromeOptions optionsChrome = new ChromeOptions(); Map prefs = new HashMap<>(); prefs.put("intl.accept_languages", browserLocale); optionsChrome.setExperimentalOption("prefs", prefs); driver = new ChromeDriver(optionsChrome) – Primal Nov 18 '19 at 05:35
  • Possible duplicate of [Set Chrome's language using Selenium ChromeDriver](https://stackoverflow.com/questions/18645205/set-chromes-language-using-selenium-chromedriver) – Dev Nov 18 '19 at 06:28

2 Answers2

1

I think you should call option with setExperimentalOption then add the language. So it should be like:

HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--lang=ja");

I hope this will work for you.

  • Bhumit patel, Thanks for your reply. This didn't work for me. I have added comment for my post with working solution. But thank you for your reply – Primal Nov 22 '19 at 05:28
0

This is my implementation for chrome / firefox

  public WebDriver createWebDriver(BrowserType browserType) {
    switch (browserType) {
        case IE:
            return new InternetExplorerDriver();
        case CHROME:
            if (SystemUtils.IS_OS_WINDOWS) {
                System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver77.exe");
            }
            if (SystemUtils.IS_OS_LINUX) {
                System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver77");
            }
            return new ChromeDriver();
        case FIREFOX:
            if (SystemUtils.IS_OS_WINDOWS) {
                System.setProperty("webdriver.gecko.driver", "src/test/resources/drivers/geckodriver.exe");
            }
            if (SystemUtils.IS_OS_LINUX) {
                System.setProperty("webdriver.gecko.driver", "src/test/resources/drivers/geckodriver");
            }
            return new FirefoxDriver();
        default:
            throw new RuntimeException("Unsupported browserType: " + browserType);
    }
user3607293
  • 1
  • 1
  • 4