Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

selenium webdriver - How to set Browser Language using RemoteWebDriver

I'm using Selenium and have tests that randomly choose the browser they run in. I have some test that test functionality related to internationalization, so I need to have the browser specify the browser language.

My best guess is I need to use SetCapability method as part of the DesiredCapabilities class, but am not sure what capabilities are valid to set.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Conclusion / Solution

Ultimately I'll be going with using Firefox as it's support seems to be more thorough.

Here is my solution:

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

For Chrome, it's support of language is limited to ISO 639-1, meaning it only supports 2 character languages. I attempted for en-au, en-ca, etc and it seems to just add English (UK) in these cases. Here is a summary of the options I tried and their results:

var options = new ChromeOptions();
//options.AddArgument("--lang=es"); //espanol
//options.AddArgument("--lang=es-mx"); //espanol (Latinoamerica), espanol
//options.AddArgument("--lang=en-ca"); //english (UK), english (us), english
//options.AddArgument("--lang=en-au"); //english (UK), english (us), english
//options.AddArgument("--lang=en-nz"); //english (UK), english (us), english
//options.AddArgument("--lang=zh"); //english (us), english
//options.AddArgument("--lang=zh-tw"); //Chinese (Traditional Chinese), Chinese, english (us), english
//options.AddArgument("--lang=zh-hk"); //Chinese (Traditional Chinese), Chinese, english (us), english
//options.AddArgument("--lang=zh-cn"); //Chinese (Simplified Chinese), Chinese, english (us), english
options.AddArgument("--lang=fr"); //Francais (France), Francais, english (us), english
//options.AddArgument("--lang=fr-ca"); //Francais (France), Francais, english (us), english
//options.AddArgument("--lang=aus"); //Francais (France), Francais, english (us), english
desiredCap.SetCapability(ChromeOptions.Capability, options);

a


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...