【发布时间】:2018-10-11 03:23:17
【问题描述】:
我需要使用具有特定浏览器语言的远程 webdriver 启动 Firefox / Chrome。我知道如何在本地运行时做到这一点。但是是否可以通过指定浏览器语言来启动远程网络驱动程序。
【问题讨论】:
标签: selenium webdriver remotewebdriver
我需要使用具有特定浏览器语言的远程 webdriver 启动 Firefox / Chrome。我知道如何在本地运行时做到这一点。但是是否可以通过指定浏览器语言来启动远程网络驱动程序。
【问题讨论】:
标签: selenium webdriver remotewebdriver
RemoteWebDriver 就是这样完成对象创建的,
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:PORT_NUMBER/"), DesiredCapabilities.firefox());
Profiller 是这里的关键,
var fp = new FirefoxProfile();
fp.SetPreference("intl.accept_languages", "en-au");
desiredCap.SetCapability(FirefoxDriver.ProfileCapabilityName,fp.ToBase64String());
您的代码似乎特定于 chrome,因此您可以使用它,希望对您有所帮助,
var options = new ChromeOptions();
options.AddArgument("--lang=zh"); // this sets US english
desiredCap.SetCapability(ChromeOptions.Capability, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:PORT_NUMBER/"), desiredCap.chrome());
【讨论】: