6

Setting the Accepted-Lang header works fine with regular Chrome via ChromeOptions options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})

I'm trying to switch to new headless Chrome, but apparently this option has no effect when checking headers on validator.w3.org. Can I change them in another way? Anybody knows if support for this feature is coming?

Using Chrome 60, Chromedriver 2.30, Selenium 3.4.3, Python 3.6.1 on MacOS

Using this code:

from selenium import webdriver

print('Start')

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

driver.get('http://validator.w3.org/i18n-checker/check?uri=google.com#validate-by-uri+')
print('Loaded')

# Check headers in output.html file. Search for 'Request headers'
html_source = driver.page_source
file = open('output.html', 'w')
file.write(html_source)
file.close

driver.implicitly_wait(5)

# Or check headers with select
# WARNING: This fails with 'headless' chrome option!
element = driver.find_element_by_xpath("//code[@class='headers_accept_language_0']").get_attribute('textContent')
print('Element:', element)

driver.close()

print('Finish')

Thanks!

Jim B
  • 641
  • 5
  • 18
  • Did you find an answer, have the same problem – Paweł Lula Sep 07 '17 at 10:20
  • Unfortunately not yet. - One guy on the google developer blog asked the same thing without any answers: https://plus.google.com/114670839725657997273/posts/aVrAivf9jXo - I'm using at the moment a Linode server which is by default set to English, this way I was able to circumvent the issue (need English headers) Please leave a comment when you found a better fix, thx – Jim B Sep 08 '17 at 15:25

1 Answers1

0

That should be possible using the Chrome-developer-protocoll (cdp).

You can execute cdp commands using driver.execute_cdp_cmd().

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
kaliiiiiiiii
  • 925
  • 1
  • 2
  • 21