如何在Selenium远程WebDriver功能中设置浏览器语言 [英] How to set browser language in selenium remote webdriver capabilities

查看:513
本文介绍了如何在Selenium远程WebDriver功能中设置浏览器语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用具有特定浏览器语言的远程网络驱动程序来启动Firefox/Chrome.我知道如何在本地运行时执行此操作.但是可以通过指定浏览器语言来启动远程Webdriver.

I need to start Firefox / Chrome using remote webdriver with a specific browser language. I know how to do it while running locally. But is it possible to start a remote webdriver with specifying browser language.

推荐答案

这是RemoteWebDriver创建对象的方式,

This is how object creation done is RemoteWebDriver,

WebDriver driver = new RemoteWebDriver(new URL("http://localhost:PORT_NUMBER/"), DesiredCapabilities.firefox());

填充物是这里的关键,

var fp = new FirefoxProfile();
fp.SetPreference("intl.accept_languages", "en-au");
desiredCap.SetCapability(FirefoxDriver.ProfileCapabilityName,fp.ToBase64String());

您的代码似乎特定于chrome,因此您可以使用它,希望对您有所帮助,

your code seems specific to chrome so you can use this, I hope this might help you,

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());

如何使用RemoteWebDriver设置浏览器语言的可能副本

这篇关于如何在Selenium远程WebDriver功能中设置浏览器语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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