pythonhtmlselenium-webdrivertagschrome-options

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


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='...'>?


Solution

  • 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