I want to be able to test with different languages. How can I do that with chromedriver ?
Asked
Active
Viewed 1,703 times
1 Answers
1
You can do this by adding Chrome's command line switches "--lang".
You start ChromeDriver with an ChromeOption argument, e.g. --lang=es
C# code for how to start Chrome in Spanish using Selenium:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--lang=es");
ChromeDriver driver = new ChromeDriver(options);
Java:
public WebDriver getDriver(String locale){
System.setProperty("webdriver.chrome.driver", "driver/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--lang=" + locale);
return new ChromeDriver(options);
}
public void initializeSelenium() throws Exception{
driver = getDriver("es"); // two letters to represent the locale, or two letters + country
}
Michael Durrant
- 25,210
- 3
- 40
- 112