How to set browser locale with chromedriver (Python)



  • I am trying to set my browser locale by doing the following

    options = webdriver.ChromeOptions()
    options.add_argument('--lang=es')
    driver = webdriver.Chrome(executable_path=driver_location, chrome_options=options)
    

    When I browse to google the site is still displayed in english. Am I setting the "--lang" option wrong?



  • Not Working

    I've tried the --lang=us option, as suggested, but also had no success using the code below. My webpages were still being downloaded with my default language (that's not en).

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.add_argument('lang=en')
    # options.add_argument('--lang=en') 

    Working

    After some research I found this gist that finally helped me. Their solution is to use the experimental option intl.accept_languages, as follows:

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

    By doing that, pages started to be loaded with the language that I wanted.

    Also, Google Chrome source code explains that this option will actually set the HTTP header Accept-Languages to the given value. What's exactly what I wanted to do.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2