How to set browser language in selenium remote webdriver capabilities

风流意气都作罢 提交于 2019-12-13 17:30:31

问题


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.


回答1:


This is how object creation done is RemoteWebDriver,

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

Profiller is the key here,

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

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

Possible duplicate of How to set Browser Language using RemoteWebDriver



来源:https://stackoverflow.com/questions/52751691/how-to-set-browser-language-in-selenium-remote-webdriver-capabilities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!