4

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.

Charlestone
  • 1,248
  • 1
  • 13
  • 27
  • Try `login.send_keys("1", "2", "3", "4", "5")` – Andersson Nov 12 '17 at 11:38
  • Nope, the ‘3’ is still not printed even when i write it completely alone – Charlestone Nov 12 '17 at 14:37
  • 1
    How about `from selenium.webdriver.common.keys import Keys` `login.send_keys(Keys.NUMPAD3)`? – Andersson Nov 12 '17 at 14:47
  • 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 Nov 12 '17 at 16:09
  • 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 Nov 13 '17 at 07:04
  • I had the same problem with other characters and was able to find a solution here :https://stackoverflow.com/a/54802193/9188586 – Pierre Baran Feb 21 '19 at 08:16

3 Answers3

7

Updating to latest chrome driver resolved this issue.

tread
  • 10,133
  • 17
  • 95
  • 170
Mudra
  • 86
  • 1
  • 3
    It is a bug in a previous version of the software. It's an entirely reasonable answer to say they should update to the latest version of the software. – titusfortner Dec 06 '17 at 18:50
1

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'")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    it should be `document.getElementById('login_credit').value='12345'` or `document.getElementsById('login_credit')[0].value='12345'` and yes, this works too, thanks! :D kinda ugly solution though – Charlestone Nov 13 '17 at 13:29
0

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)
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36