开发者

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

I've been looking for a while and still haven't found anything. When I run my Selenium tests from within Eclipse, it opens up a Firefox browser which always has English as its default locale. Changing default browser settings doesn't change the fact that each new browser opened by Selenium has an English locale.

I haven't found any way in the API to set something other than English as my locale. I've tried setting the locale as a VM parameter for the Selenium server, I've tried setting it for my tests.

There's got to be some obvious way of doing this that I'm missing that will resu开发者_Go百科lt in easy rep for you. :) Any thoughts?


My idea to solve this...

Create Firefox Profiles and open them with Selenium. You can modify them for your needs.

Selenium Documentation

By using specific profiles you can avoid this issue. It is not a "nice and clean" Solution..but it works...at least for me.


Now you may 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)
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜