How to set the browser locale for Selenium tests running in Java?

I was looking for a while and found nothing. When I run Selenium tests from Eclipse, it opens the Firefox browser, which always has English by default. Changing the default browser settings does not change the fact that every new browser opened by Selenium has English.

I did not find any way in the API to install something other than English as my language. I tried to set the locale as the VM parameter for the Selenium server, I tried to set it for my tests.

There must be some obvious way to do this that I will miss, which will lead to an easy reputation for you. :) Any thoughts?

+4
source share
2 answers

My idea is to solve this problem ...

Create Firefox profiles and open them with Selenium. You can change them for your needs.

Selenium documentation

Using certain profiles, you can avoid this problem. This is not a "good and clean" solution ... but it works ... at least for me.

+5
source

Now you can use the following snippet for ChromeDriver (in Scala):

private def createDriver(): RemoteWebDriver = { val prefs = new util.HashMap[String, Any]() prefs.put("intl.accept_languages", "en") val options = new ChromeOptions() options.setExperimentalOption("prefs", prefs) options.setBinary(chromePath) new ChromeDriver(options) } 
+2
source

All Articles