python's selenium "send_keys" with chrome driver drops characters python's selenium "send_keys" with chrome driver drops characters selenium selenium

python's selenium "send_keys" with chrome driver drops characters


Looks like there are (were) some bugs in the Chrome webdriver: https://code.google.com/p/chromedriver/issues/detail?id=435

The core of the problem looks to be when either the keyboard is configured for a non-English language, or if the webdriver process and the chrome display are running in different language/environments (e.g., when going through a remote display from one host to another, etc.)


I've solved using a custom method for send_keys, which works a little bit lower but fast enough.

from selenium.webdriver.remote.webelement import WebElementdef send_keys(el: WebElement, keys: str):    for i in range(len(keys)):        el.send_keys(keys[i])send_keys(el, keys)


I ran into a similar problem as OP and was satisfied with none of the answers written here nor anywhere else on this site that I could find.Since I read during my research that the issue was at some point in time fixed, I have to assume that it re-appeared nowadays.

As P.T. mentioned, if you run into similar problems, chances are the chromedrivers/firefoxdrivers are buggy again.

Since none of the solutions I found helped alleviate the issue, I instead opted for just circumventing selenium and its drivers altogether. So I used javascript to first find the element (through its absolute Xpath), then write to it / set it.

from selenium import webdriverdef write_to_element(driver, element_xpath, input_string),         js_command = f'document.evaluate(\'{xpath}\', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.value = \'{input_string}\';'        driver.execute_script(js_command)driver = webdriver.Chrome()driver.get('WebPage/With/Element/You/Want/To/Write/To')xpath = 'Xpath/Of/Element/You/Want/To/Write/To'write_to_element(driver, xpath, 'SomeRandomInput')

document.evaluate(\'{xpath}\', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null) evaluates the xpath to an element, so essentially finds your element on the webpage.

.singleNodeValue.value = \'{input_string}\';' sets the value of that element to input_string