fadingbeat
fadingbeat

Reputation: 433

Set browser locale in headless chrome with python

I'm running headless chrome with python script, from docker container. Browser is opening in local language, instead of the language I have specified within the code.

I am using experimental option, but it doesn't work.

options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})

This doesn't work either:

options.add_argument('--lang=es')

Or this:

browser_locale = 'en'
options.add_argument("--lang={}".format(browser_locale))

Help appreciated.

Upvotes: 0

Views: 618

Answers (1)

fadingbeat
fadingbeat

Reputation: 433

Eventually, I found the solution to be this:

In my create_driver method, I added self.driver.get("https://www.google.com/ncr") which resolved the issue of opening the browser in the local language.

NCR stands for NoCountryRedirect.

Upvotes: 1

Related Questions