如何在Selenium Automation中更改Chrome浏览器语言 [英] How to change chrome browser language in selenium automation

查看:542
本文介绍了如何在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

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

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