How to modify the website language using selenium python bindings.

--

How can I modify the language option in selenium python bindings?

I’ve tried the — lang, but it didn’t work for me:

Not Working:

chrome_options.add_argument("--lang=en")
OR
chrome_options.add_argument("--lang=en-US")

After some research, I found that to solve this, we have to use the experimental option intl.accept_languages:

Working Solution:

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

Note: To use above, your website should need to support the same.

There is one more way to achieve the same by translating your native language page to english:

Try using below code:

prefs = {
"translate_whitelists": {"your native language":"en"},
"translate":{"enabled":"True"}
}
options.add_experimental_option("prefs", prefs)

Ref: https://stackoverflow.com/questions/55150118/trouble-modifying-the-language-option-in-selenium-python-bindings/55254431#55254431

--

--