Skip to content
Advertisement

How can i set browser language in Selenide using Java?

Hello guys please how can i do it?When i run not headless mode browser is in english and everything works fine, but when i run headless mode language is changed to my native language.

I am using this for headless mode.

   Configuration.headless = true;

Advertisement

Answer

Selenide Configuration class contains

public static MutableCapabilities browserCapabilities which used within the driver startup if provided.

For Chrome:

ChromeOptions options = new ChromeOptions()
    .setHeadless(true)
    .addArguments("--lang=en_US");
Configuration.browserCapabilities = options;

But note --lang argument might be ignored on Linux.

For Firefox:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", "en-US");
FirefoxOptions options = new FirefoxOptions()
    .setHeadless(true);
    .setProfile(profile);
Configuration.browserCapabilities = options;
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement