Hello,
Recently, I’ve encountered a problem with RF. I am testing a global brand’s website which supports many languages. I wanted to test the danish site, but it switches automatically to english after a keyword.
How to troubleshoot this? ChatGPT could not help me to this problem.
Would be great if someone has a solution 
Hello oustdrancy,
welcome to the forum.
It seems to be habit of nowadays internet that services override user choice with assumptions. The website likely tries to estimate which language you prefer. Question is what source does the website use for making the assumption that you want to view the website in English instead of Danish.
Maybe it uses the locale of the browser context.
Try
New Context locale=da-DK
Kind regards,
Markus
1 Like
Thank you Markus.
Unfortunately, it didn’t quite work. But I am not sure if this is the right way to use it:
Setup
[Documentation] Test Setup
New Browser chromium headless=False
New Context locale=da-DK
New Page ${URL}
Yes this correct use of the New
keywords. Then maybe the websites has other means to “auto-correct” the language. I am not deep enough in web-development, though. I don’t know if chrome has more settings that could be tweaked. Maybe the website uses the IP address to guess the country it is accessed from.
I don’t know, sorry.
2 Likes
I have this old test for SeleniumLibrary, maybe you can use some info:
*** Settings ***
Documentation \ I have a challenge
... I’m running Chrome version 67.0.3396.87. I’m running the below code; however,
... the browser does not open in the desired language (fr-ca or ja).
... https://robotframework.slack.com/messages/@U6SDCR92S
...
... Reference page:
... https://www.w3.org/International/questions/qa-lang-priorities
...
... Firefox:
... "intl": "accept_languages": "pt-PT,pt,en,en-us"
... Accept-Language: pt-PT,pt;q=0.8,en;q=0.5,en-US;q=0.3
Suite Teardown Close All Browsers
Force Tags lang_test
Task Tags teste
Library SeleniumLibrary
*** Test Cases ***
Set Chrome to fr-ca
Switch language For Chrome https://www.wikipedia.org/ fr-ca
Sleep 3 seconds
Capture Page Screenshot
[Teardown] Close Browser
Set Chrome to ja
Switch language For Chrome https://www.wikipedia.org/ ja
Sleep 3 seconds
Capture Page Screenshot
[Teardown] Close Browser
Set Chrome to pt-pt
Switch language For Chrome https://www.wikipedia.org/ pt-PT
Sleep 3 seconds
Capture Page Screenshot
[Teardown] Close Browser
*** Keywords ***
Switch language For Chrome
[Arguments] ${url} ${locale}
[Documentation] Starts a Chrome Browser with specified locale
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys
Call Method ${options} add_argument --lang\=${locale}
Call Method ${options} add_argument user-agent\=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17
Create webDriver Chrome chrome_options=${options}
&{prefs}= Create Dictionary intl.accept_languages=${locale},en,en-us
Call Method ${options} add_experimental_option prefs ${prefs}
Create Webdriver Chrome chrome_options=${options}
GoTo ${url}
1 Like