Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Headless Chrome and Language Setup

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.

like image 569
Pascal Schott Avatar asked Aug 30 '26 00:08

Pascal Schott


1 Answers

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')

Reference

You can find a relevant detailed discussion in:

  • Issue 1925: Expose content settings in headless mode
like image 165
undetected Selenium Avatar answered Aug 31 '26 15:08

undetected Selenium