I'm trying to test my website with Selenium but I don't manage to change the language of the browser. I tried with Firefox, changing the profile also but it's not working.
That's a pity because much of my content is changing regarding the language.
Here is my Python code:
@classmethod
def setUpClass(cls):
super(SeleniumTestCase, cls).setUpClass()
options = Options()
options.add_argument('--lang=en')
cls.selenium = WebDriver(chrome_options=options)
So normally I change the language but nothing happens...
Just to clarify. I already checked on stackoverflow and if I post this question it's really because I tried most of the solutions I saw.
In Selenium, we can modify the language preferences with the help of ChromeOptions class for the Chrome browser. We shall create an object of this class and apply addArguments method on it. To modify the language to Spanish, we have to pass −−lang=es as a parameter to the addArguments method.
Mozilla Firefox is one of the most widely used browsers in the world. It has enhanced features and is supported by a multitude of the latest testing tools and techniques. One such tool is Selenium.
FIREFOX JAVA
Java code for changing the language to English:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", "en-GB");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
driver = new FirefoxDriver(options);
CHROME JAVA
Java code for changing the language to English:
ChromeOptions options = new ChromeOptions();
options.addArguments("lang=en-GB");
driver = new ChromeDriver(options);
FIREFOX PYTHON
options = Options()
options.set_preference('intl.accept_languages', 'en-GB')
browser = webdriver.Firefox(options=options)
The answer is already available in one of the very recent post:
Change language on Firefox with Selenium Python
Here is the code:
def get_webdriver(attempts=3, timeout=60, locale='en-us'):
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("intl.accept_languages", locale)
firefox_profile.update_preferences()
desired_capabilities = getattr(
DesiredCapabilities, "FIREFOX").copy()
hub_url = urljoin('http://hub:4444', '/wd/hub')
driver = webdriver.Remote(
command_executor=hub_url, desired_capabilities=desired_capabilities,
browser_profile=firefox_profile)
return driver
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With