Need to control chromedriver chrome language, but chrome_options can't be passed along
See original GitHub issueIssue Description
Hello,
Try to use chrome instead of firefox as it is faster and because firefox stop working recently for apparently selenium/splinter/firefox update missmatch of some kind…
I have ubuntu with french locales and chrome seems to be installed with french as a default language… My tests need to be executed in us-en chrome instance to succeed. Even if I set default language to us_en in chrome preferences the instance lauched by browser(‘chrome’) don’t seems to use the default profile preferences but the chrome built one or something.
So, I try many way to pass language specification to chrome instance without succes.
from splinter.driver.webdriver.chrome.Options import Options
import splinter
options = splinter.driver.webdriver.chrome.Options()
options.add_argument('--lang=en-us')
browser = Browser('chrome', chrome_options=options)
Inspire by some answer from this SO question : http://sqa.stackexchange.com/questions/9904/how-to-set-browser-locale-with-chromedriver-python
Not working…
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from splinter.driver.webdriver import BaseWebDriver, WebDriverElement
options = Options()
options.add_argument('--lang=en-us')
global browser
browser = BaseWebDriver()
browser.driver = Chrome(chrome_options=options)
This other option failed with the following error :
do_login_if_need(username, base64.b64decode(password))
controllers/test_analysis.py:180: controllers/test_analysis.py:90: in do_login_if_need if browser.is_element_present_by_css(‘div.login_box’): /usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/init.py:251: in is_element_present_by_css return self.is_element_present(self.find_by_css, css_selector, wait_time) /usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/init.py:237: in is_element_present if finder(selector): /usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/init.py:387: in find_by_css original_query=css_selector)
self = <splinter.driver.webdriver.BaseWebDriver object at 0x7fd3bc2b8d90> finder = <bound method WebDriver.find_elements_by_css_selector of <selenium.webdriver.chrome.webdriver.WebDriver (session=“e32ee751b41d469e5138fac42c7d25e4”)>>, selector = ‘div.login_box’, original_find = ‘css’ original_query = ‘div.login_box’
def find_by(self, finder, selector, original_find=None, original_query=None):
elements = None
end_time = time.time() + self.wait_time
func_name = getattr(getattr(finder, _meth_func), _func_name)
find_by = original_find or func_name[func_name.rfind('_by_') + 4:]
query = original_query or selector
while time.time() < end_time:
try:
elements = finder(selector)
if not isinstance(elements, list):
elements = [elements]
except NoSuchElementException:
pass
if elements:
return ElementList(
[self.element_class(element, self) for element in elements], find_by=find_by, query=query)
E AttributeError: ‘BaseWebDriver’ object has no attribute ‘element_class’
/usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/init.py:380: AttributeError
I am not sure if It is me that don’t follow proper API fo BaseWebDriver or if the issue is somewhere else…
I think issues #326 and #382 are relate to mine…
Thanks
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (1 by maintainers)
Hi @BuhtigithuB,
A bit late, but just in case you still need it, I found that
options.add_experimental_option("prefs", {"intl.accept_languages": "fr-FR"})
works.Karl
In Ruby, I used it this way if that can help anyone