4
votes

For some reason, I am unable to write character '3' into the input element on the page.

This code:

    chrome_options = Options()
    chrome_options.add_argument('--dns-prefetch-disable')
    chrome_options.add_argument('--no-proxy-server')
    chromeDriverPath = self.getChromeDriverPath()
    os.environ["webdriver.chrome.driver"] = chromeDriverPath
    self.driver = webdriver.Chrome(chromeDriverPath, chrome_options=chrome_options)

    self.driver.get(self.loginUrl)
    login = self.driver.find_element_by_id('login_credit')
    login.send_keys("12345")

results in "1245" being written in the login input... Can someone help please? I use python 2.7, the latest chrome and the latest chromedriver

EDIT:

login.send_keys("3")

login.send_keys("\3")

don't work either.

login.send_keys("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()")

- only the "3" was missing in the string...

what worked was

login.send_keys(Keys.NUMPAD3)

as Andersson suggested below, but this is not a solution.

I tried it in the google search box and I experienced the same behaviour.

3
Try login.send_keys("1", "2", "3", "4", "5") - Andersson
Nope, the ‘3’ is still not printed even when i write it completely alone - Charlestone
How about from selenium.webdriver.common.keys import Keys login.send_keys(Keys.NUMPAD3)? - Andersson
change your script to open a public website like google and send keys 12345 to input box, if 3 still missing, the problem most possible from chrome and chromedriver. Then try other version chrome or chromedriver. - yong
wow, the Keys.NUMPAD3 actually worked :D. But I wont accept it as an answer - I don't want to parse strings and send it char by char, if you know what I mean. The problem occurs in all input boxes I tried (google etc.) - Charlestone

3 Answers

6
votes

Updating to latest chrome driver resolved this issue.

1
votes

Instead of using send_keys("12345") you can use any of the alternatives mentioned below :

  1. Use Keys.NUMPAD3 :

    login.send_keys(Keys.NUMPAD3)
    
  2. Use JavascriptExecutor with getElementById :

    self.driver.execute_script("document.getElementById('login_credit').value='12345'")
    
  3. Use JavascriptExecutor with getElementsById :

    self.driver.execute_script("document.getElementsById('login_credit')[0].value='12345'")
    
0
votes

Strange issue, Try to pass string variable in send_keys and try may be it works for you

my_str = "12345"
login = self.driver.find_element_by_id('login_credit')
login.send_keys(my_str)