The send_keys()
method works as it should in my windows setup, but I constructed a little method that might solve your problem. It is, like other have already suggested, using the selenium.webdriver.common.keys.Keys
constants:
def send_keys_workaround(element, string):
for s in string:
if s == '5':
element.send_keys(Keys.NUMPAD5)
elif s == '6':
element.send_keys(Keys.NUMPAD6)
else:
element.send_keys(s)
I have set up a minimalistic jsfiddle, to test if it works on windows at least. I hope it will work on your Ubuntu too. The full script is here:
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
def send_keys_workaround(element, string):
for s in string:
if s == '5':
element.send_keys(Keys.NUMPAD5)
elif s == '6':
element.send_keys(Keys.NUMPAD6)
else:
element.send_keys(s)
driver = WebDriver("****INSERT PATH TO CHROMEDRIVER***")
driver.get("http://jsfiddle.net/zwktb7tn/")
wait = WebDriverWait(driver, 20, 2)
wait.until(expected_conditions.frame_to_be_available_and_switch_to_it((By.NAME, 'result')))
element = driver.find_element_by_id('inputfield')
send_keys_workaround(element, "123456")
r'12345'
, any other string interpretations should be ignored. It can be useful for writing the correct path names in Windows.