i'm working with selenium and the chrome driver in python. I can setup the language of my chrome browser like this:
options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})
This works like a charm, but as soon as i add the headless argument i get results in german again:
options.add_argument("--headless")
Thank you guys for your time.
Using google-chrome-headless to set the language pass the --lang
command using an instance of Options()
as follows:
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--lang=en_US')
You can find a relevant detailed discussion in:
there is no tags for debian but still, maybe it will help someone.
Installed the web browser - language packs
. The package is called chromium-l10n
on Debian 11.
Made sure the locale i want is shown via locale -a
(uncomment in /etc/locale.gen
and use locale-gen
).
Started the python program via:
LANGUAGE=de programname.py
as alternative, setting LANGUAGE
inside the python also worked.
from os import environ environ['LANGUAGE'] = 'de'
This made it work in Headless mode.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.