Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7842889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:25:31+00:00 2026-06-02T16:25:31+00:00

I want to execute my Selenium tests in different languages. Is it possible to

  • 0

I want to execute my Selenium tests in different languages. Is it possible to change the language of an existing WebDriver at runtime or do I have to recreate the browser instance?

Right now I’m only using Firefox, but I want to execute tests in different browsers at some later point.

In Firefox I set the language like this:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", "de");
WebDriver driver = new FirefoxDriver(profile);

I also implemented a WebDriverPool, which holds a WebDriver instance so it can be shared among tests. If the language can only be set at creation time, I could hold an instance for every locale.

All in all I wonder if I miss something here. Why is it so hard to change the language? shouldn’t there be a method like WebDriver.setAcceptLanguages(Locale)?

In a nutshell I have these questions:

  1. Why isn’t there WebDriver.setAcceptLanguages(Locale)?
  2. How to change the language for the dirrerent WebDrivers?
  3. Can I change the language at runtime?
  4. How did you guys implement your WebDriverPool or do you recreate them everytime?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:25:33+00:00Added an answer on June 2, 2026 at 4:25 pm

    I ended up creating a WebDriverPool that creates one instance for every combination of WebDriver type (e.g. FirefoxDriver.class) and Locale (e.g. en_US). Maybe this is usful for someone.

    public class WebDriverPool {
    
      private Map<String, WebDriver> drivers = new HashMap<String, WebDriver>();
      private List<WebDriver> driversInUse = new ArrayList<WebDriver>();
    
      public WebDriverPool() {
        Runtime.getRuntime().addShutdownHook(new Thread(){
          @Override
          public void run(){
            for (WebDriver driver : drivers.values())
              driver.close();
    
            if (!driversInUse.isEmpty())
              throw new IllegalStateException("There are still drivers in use, did someone forget to return it? (size: " + driversInUse.size() + ")");
          }
        });
      }
    
      private WebDriver createFirefoxDriver(Locale locale){
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("intl.accept_languages", formatLocale(locale));
        return new FirefoxDriver(profile);
      }
    
      private String formatLocale(Locale locale) {
        return locale.getCountry().length() == 0
          ? locale.getLanguage()
          : locale.getLanguage() + "-" + locale.getCountry().toLowerCase();
      }
    
      /**
       * @param clazz
       * @param locale
       * @return web driver which can be new or recycled
       */
      public synchronized WebDriver getWebDriver(Class<? extends WebDriver> clazz, Locale locale){
    
        String key = clazz.getName() + "-" + locale;
    
        if(!drivers.containsKey(key)){
    
          if(clazz == FirefoxDriver.class){
            drivers.put(key, createFirefoxDriver(locale));
          }
    
          // TODO create other drivers here ...
    
          // else if(clazz == ChromeDriver.class){
          //     drivers.put(key, createChromeDriver(locale));
          // }
    
          else{
            throw new IllegalArgumentException(clazz.getName() + " not supported yet!");
          }
        }
    
        WebDriver driver = drivers.get(key);
    
        if(driversInUse.contains(driver))
          throw new IllegalStateException("This driver is already in use. Did someone forgot to return it?");
    
        driversInUse.add(driver);
        return driver;
      }
    
      public synchronized void returnWebDriver(WebDriver driver){
        driversInUse.remove(driver);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have a typical web application stack. there are 120 selenium (webdriver) tests that
I am using Selenium WebDriver and want to execute some javascript from a webpage.
I'm testing a page with Selenium IDE and want to execute a method already
I have asp.net generated html code. I want execute jQuery click function when user
I want to execute some Python code, typed at runtime, so I get the
I want to execute the DeviceInformation command on iOS devices. So far I have
I want to execute a command when a process dies. I have a solution
I want to execute the following: $('#AccountID').change(SelectAccounts); and then (SelectProducts) Is there some way
I want to execute a php-script from php that will use different constants and
I want to execute something in a linux shell under a few different conditions,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.