How to modify the website language using selenium python bindings.
Mar 7, 2023
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)