如何在 selenium 自动化中更改 chrome 浏览器语言

Vij*_*jah 4 selenium localization selenium-chromedriver selenium-webdriver

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

Vij*_*jah 5

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

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");
Run Code Online (Sandbox Code Playgroud)

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

  • 请参阅此 /sf/ask/3530996801/#50442825 以了解 Firefox 浏览器更改 (4认同)