Set Chrome's language using Selenium ChromeDriver

后端 未结 7 1328
囚心锁ツ
囚心锁ツ 2020-12-05 18:24

I download ChromeDriver and by defaults the browser language is in English, I need to change it to Spanish, and I have been unable.

public WebDriver getDrive         


        
7条回答
  •  误落风尘
    2020-12-05 18:34

    For me, --lang didn't work. It seems to set the language of the first opened tab, all others chrome processes are started with --lang=en-US.

    What did work is the following:

    DesiredCapabilities jsCapabilities = DesiredCapabilities.chrome();
    ChromeOptions options = new ChromeOptions();
    Map prefs = new HashMap<>();
    prefs.put("intl.accept_languages", language);
    options.setExperimentalOption("prefs", prefs);
    jsCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
    

提交回复
热议问题