How to get language of website in selenium(python)?

461 Views Asked by At

I set the language in Selenium using: chrome_options.addargument("--lang=en").

However, in test I need to check that language is really English.

Maybe I can check it from <html lang='...'>?

1

There are 1 best solutions below

0
On BEST ANSWER

I use this to get the browser language as a string:

from selenium import webdriver
driver = webdriver.Chrome()
language = driver.find_element(By.XPATH, "//html").get_attribute('lang')

Hope that helps