Charlestone
Charlestone

Reputation: 1260

Chrome webdriver send keys does not send '3'

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.

Upvotes: 4

Views: 4567

Answers (3)

Mudra
Mudra

Reputation: 86

Updating to latest chrome driver resolved this issue.

Upvotes: 7

undetected Selenium
undetected Selenium

Reputation: 193078

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'")
    

Upvotes: 1

iamsankalp89
iamsankalp89

Reputation: 4739

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)

Upvotes: 0

Related Questions