Nagasaki45 Nagasaki45 - 2 years ago 317
Python Question

Selenium send_keys doesn't work if input type="number"

I'm writing tests using selenium. In those tests I need to enter a number into a field in a form.

Here is the html:

<!DOCTYPE html>

<input type="number" id="field_id">


And the code:

browser = webdriver.Firefox()
field = browser.find_element_by_id('field_id')
field.send_keys('12') # NOTHING HAPPEN!

BTW, if I change the type of the field to "text" for example there is no problem at all. In addition,
work great (but doesn't work when I'm using bootstrap) and
work all the time, as well as

Selenium version: 2.41.0
Firefox version: 29.0

Answer Source

Because you are using Firefox 29. Please downgrade to Firefox 28, which is the one Selenium 2.41.0 supports to, see CHANGES file. Otherwise you need to wait for new Selenium updates.

Here is what I have tested working with Firefox 28:

from selenium import webdriver

    <form><input type="number" id="field_id"></form>

browser = webdriver.Firefox()

input_number = browser.find_element_by_id('field_id')

input_number_value = input_number.get_attribute('value')
print "input_number_value = " + input_number_value

See also: Selenium can't find fields with type number

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download