WebDriver:如何为Chrome指定首选语言 [英] WebDriver: How to specify preferred languages for Chrome

查看:232
本文介绍了WebDriver:如何为Chrome指定首选语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的远程chrome驱动程序以德文而不是英文请求页面。遵循 chromedriver文档 chrome首选项列表,我尝试将其设置为:

  capabilities.setCapability(ChromeOptions.CAPABILITY,getChromeOptions()); 
Map< String,String> chromePrefs = new HashMap< String,String>();
chromePrefs.put(settings.language.preferred_languages,de-DE,de);
capabilities.setCapability(chrome.prefs,chromePrefs);

我可以看到它从日志文件到达chromedriver:

  [0.453] [FINE]:使用功能初始化会话{
browserName:chrome,
chrome.prefs:{
settings.language.preferred_languages:de-DE,de
},
chromeOptions:{
args:[--ignore-certificate-错误],
extensions:[]
},
platform:ANY,
version:null
}

但它仍然会要求英文页面,并且可以通过在首选项中打开内容设置来查看。我做错了什么?

解决方案

(Edit) b
$ b


  1. intl.accept_languages 是处理请求的语言。
  2. 使用(更新和首选的) ChromeOptions 设置首选项的功能。 strong>机制(否则,如果有任何ChromeOptions由您或您的语言绑定设置,则无法运行,请参阅问题 104 & 95 < a>)。

    尚未完全实施ChromeOptions对设置偏好设置的支持。因此,不幸的是,您必须使用我的脏解决方法 =nofollow>评论6至第95期



    替代方案可能是用所需的语言设置创建用户个人资料并使用ChromeOption设置(命令行)选项以使用此配置文件,如 chromedriver中所述功能维基页面


I'm trying to get my remote chrome driver to request pages in German instead of English. Following the chromedriver documentation and list of chrome preferences, I tried to set it like this:

    capabilities.setCapability(ChromeOptions.CAPABILITY, getChromeOptions());
    Map<String, String> chromePrefs = new HashMap<String,String>();
    chromePrefs.put("settings.language.preferred_languages", "de-DE,de");
    capabilities.setCapability("chrome.prefs", chromePrefs);

And I can see it reaches chromedriver from the log file:

[0.453][FINE]:      Initializing session with capabilities {
   "browserName": "chrome",
   "chrome.prefs": {
      "settings.language.preferred_languages": "de-DE,de"
   },
   "chromeOptions": {
      "args": [ "--ignore-certificate-errors" ],
      "extensions": [  ]
   },
   "platform": "ANY",
   "version": null
}

But it still requests english pages and this can also be seen by opening the content settings in the preferences. What am I doing wrong?

解决方案

(Edit) Long story short:

  1. intl.accept_languages is the preferences key to manipulate what languages are requested for a page.
  2. Set the capability for the preferences using the (newer and preferred) ChromeOptions mechanism (otherwise it won't work if any ChromeOptions are set by you or your language bindings, see Issues 104 & 95).

    ChromeOptions support for setting preferences is not completely implemented yet. So, unfortunately, you have to use the dirty workaround from my comment 6 to Issue 95

    An alternative might be to create a user profile with the desired language settings and use ChromeOption to set the (command line) option to use this profile, as mentioned on the chromedriver capabilities wiki page.

这篇关于WebDriver:如何为Chrome指定首选语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆