selenium change language browser chrome / firefox

后端 未结 4 1924
一个人的身影
一个人的身影 2021-02-09 13:05

I\'m trying to test my website with selenium but I don\'t manage to change the language of the browser. I tried with firefox, changing the profile also but it\'s not working.

4条回答
  •  旧巷少年郎
    2021-02-09 14:03

    The answer is already available in one of the very recent post:
    Change language on Firefox with Selenium Python

    Here is the code:

    def get_webdriver(attempts=3, timeout=60, locale='en-us'):
      firefox_profile = webdriver.FirefoxProfile()
      firefox_profile.set_preference("intl.accept_languages", locale)
      firefox_profile.update_preferences()
    
      desired_capabilities = getattr(
          DesiredCapabilities, "FIREFOX").copy()
    
      hub_url = urljoin('http://hub:4444', '/wd/hub')
      driver = webdriver.Remote(
        command_executor=hub_url, desired_capabilities=desired_capabilities,
        browser_profile=firefox_profile)
    
      return driver
    

提交回复
热议问题