Map<String, Object> langs = new HashMap<String, Object>();
langs.put("en", selectedLanguage);
prefs.put("translate", "{'enabled' : true}");
prefs.put("translate_whitelists", langs);
Coptions.setExperimentalOption("prefs", prefs);
driver = new ChromeDriver(Coptions);
After Added the page content is not change. please give me any suggestions on this.
CodePudding user response:
The above approach doesn't work anymore with Chrome. Below you can find a way that currently works. The language code can be taken from here
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("intl.accept_languages", "LANGUAGE_CODE");
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
CodePudding user response:
public class Testing {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\Admin\\Desktop\\chromedriver\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.addArguments("−−lang=bn");
Map<String, Object> prefs = new HashMap<String, Object>();
Map<String, Object> langs = new HashMap<String, Object>();
langs.put("en", "bn");
prefs.put("translate", "{'enabled' : 'true'}");
prefs.put("translate_whitelists", langs);
prefs.put("intl.accept_languages", "bn");
opt.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(opt);
driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);
// driver.get("https://www.facebook.com/");
// driver.get("https://www.icicibank.com/");
// driver.get("https://twitter.com/i/flow/login");
driver.get("https://www.goibibo.com/");
}
}