如何在Selenium Automation中更改Chrome浏览器语言

如何在Selenium Automation中更改Chrome浏览器语言

问题描述:

我想自动化Web应用程序的本地化功能.当浏览器语言更改时,根据我的应用程序,应用程序语言应根据浏览器语言自动更改.该怎么做?

I want to automate localization functions of a web application. According to my application when the browser language changes, application language should change automatically according to the browser language. How to do that?

在启动驱动程序之前,请在chrome选项中设置语言代码,如下所示.

Set the language code in chrome options before launching the the driver as shown below.

System.setProperty("webdriver.chrome.driver","<PATH>/chromedriver.exe");
ChromeOptions chromeoptions = new ChromeOptions();
// for japanese language
chromeoptions.addArguments("–lang= ja");
ChromeDriver driver = new ChromeDriver(chromeoptions);
driver.get("https://www.google.com");

对于语言代码: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes