Not Working

I’ve tried the --lang=us option, as suggested, but also had no success using the code below. My webpages were still being downloaded with my default language (that’s not en).

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('lang=en')
# options.add_argument('--lang=en') <- Tried this option as well
driver = webdriver.Chrome(chrome_options=options)

Working

After some research I found this gist that finally helped me. Their solution is to use the experimental option intl.accept_languages, as follows:

from selenium import webdriver

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

By doing that, pages started to be loaded with the language that I wanted.

Also, Google Chrome source code explains that this option will actually the HTTP header Accept-Languages to the given value. What’s exactly what I wanted to do.



Source link https://sqa.stackexchange.com/questions/9904/how-to-set---with--

LEAVE A REPLY

Please enter your comment!
Please enter your name here