How to pass language setting to Chrome webdriver?

8,587 views
Skip to first unread message

Tset Noitamotua

unread,
Nov 4, 2015, 8:45:14 AM11/4/15
to robotframework-users
Hi guys!

Does somebody know how to pass the chomeOption '--lang=xx' to Chrome webdriver?

I have made this keyword:

| Open URL in Google Chrome | [Arguments] | ${url}
| | [Documentation] | Starts the Google Chrome browser.
| | ${options}= | Evaluate | sys.modules['selenium.webdriver'].ChromeOptions() | sys, selenium.webdriver
| | Call Method | ${options} | add_argument | --lang=de
| | Create WebDriver | Chrome | chrome_options=${options}
| | Go To | ${url}


When I use this keyword I get this error:

TRACE: Arguments: [ <selenium.webdriver.chrome.options.Options object at 0x03307270> | 'add_argument' | --lang='de' ]

FAIL
: Calling method 'add_argument' failed: TypeError: add_argument() got an unexpected keyword argument '--lang'


How can I make chromedriver to start with German locale instead of it's default English?
a
Cheers
Tset

Tset Noitamotua

unread,
Nov 4, 2015, 9:40:22 AM11/4/15
to robotframework-users
My solution so far in Python interactive shell:

from selenium import webdriver
lang_de
= webdriver.ChromeOptions()
lang_de
.add_argument("--lang=de")
chrome
= webdriver.Chrome(chrome_options=lang_de)

This starts a Chrome browser with German locale.

Now I need to translate this into Robot Framework syntax.

Cheers
Tset

Tset Noitamotua

unread,
Nov 4, 2015, 9:59:46 AM11/4/15
to robotframework-users
Final solution in Robot Framework syntax:

| Open URL in Google Chrome | [Arguments] | ${url}
| | [Documentation] | Starts the Google Chrome browser.
| | ${options}= | Evaluate | sys.modules['selenium.webdriver'].ChromeOptions() | sys
| | Call Method | ${options} | add_argument | --lang\=de
| | Create WebDriver | Chrome | chrome_options=${options}
| | Go To | ${url}


Actually I just needed to escape the equal sign: instead '--lang=de' one need to write '--lang\=de'

Cheers
Tset

Hélio Guilherme

unread,
Nov 4, 2015, 10:50:47 AM11/4/15
to robotframework-users
Thanks, for sharing the problem, hypothesis, experimentation and conclusion.
Gallileu Gallilei would be proud of you!

(really, that example would be nice to have in an advanced blog or wiki about RF/S2L)


--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Tatu Aalto

unread,
Nov 4, 2015, 1:10:45 PM11/4/15
to Hélio Guilherme, robotframework-users

Ugh

That would be nice example to the keyword documentation.

-Tatu
Send from my mobile

Tatu Aalto

unread,
Nov 5, 2015, 1:35:21 AM11/5/15
to Hélio Guilherme, robotframework-users

Ugh

Did open a issue [1], so that we actually remember to decide and perhaps implemented the improvement.

-Tatu
Send from my mobile

[1] https://github.com/robotframework/Selenium2Library/issues/529

Igor Radovanovic

unread,
Nov 13, 2015, 9:11:27 AM11/13/15
to robotframework-users
Regarding your python code - do you need to return something from python?
Because for me browser is opened, language is correct but that's all. No possible more interaction with browser.
If I try robotcode then I can't set user-data-dir (iI need also user data dir)
Some help?

Tset Noitamotua

unread,
Nov 13, 2015, 10:18:16 AM11/13/15
to robotframework-users
@Igor: What do you meen by "No possible more interaction with browser"?

Try all these steps in Python interactive shell:

from selenium import webdriver
lang_de
= webdriver.ChromeOptions()
lang_de
.add_argument("--lang=de")
chrome
= webdriver.Chrome(chrome_options=lang_de)
chrome.get("http://www.google.com")
search_input = chrome.find_element_by_xpath("//input[@class='gsfi']")
search_input.send_keys("I love Python!")
search_button = chrome.find_element_by_xpath("//button[@class='lsb']")
search_button.click()

See the magic? ;-)

I am using this mainly to check whether the locator or xpath expression I´m planning to use in test code is working correctly.

Cheers
Tset


Am Mittwoch, 4. November 2015 14:45:14 UTC+1 schrieb Tset Noitamotua:

Igor Radovanovic

unread,
Nov 13, 2015, 10:46:31 AM11/13/15
to robotframework-users
Ok. My mistake. I forget to mention that I'm using robot framework to write test, but Ii have some, let's say, a custom library from where I execute python code calling it from ROBOT.
So I call this method, to run chrome and then I want to continue with robot keywords execution...
Like when you have in robot:

Open Browser  url   browser
GoTo   google2.com

Payam Pirooznia

unread,
Oct 25, 2017, 5:02:10 PM10/25/17
to robotframework-users
Thank you so much!

vedashree paranjape

unread,
Jun 29, 2020, 11:19:29 AM6/29/20
to robotframework-users
Thanks Alot!
It works also for --user-data-dir\=,  --log-path\=.
This solution should work for any argument which throw the given error:  FAIL: Calling method 'add_argument' failed: TypeError: add_argument() got an unexpected keyword argument.

Thanks for posting!
Reply all
Reply to author
Forward
0 new messages