Selenium Headless Chrome and Language Setup

Viewed 669

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.

2 Answers

there is no tags for debian but still, maybe it will help someone.

  1. Installed the web browser - language packs. The package is called chromium-l10n on Debian 11.

  2. Made sure the locale i want is shown via locale -a (uncomment in /etc/locale.gen and use locale-gen).

  3. 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.

Related