How to change chrome browser language in selenium

2020-03-05 02:22发布

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?

1条回答
Rolldiameter
2楼-- · 2020-03-05 03:07

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

For language codes : https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

查看更多
登录 后发表回答