Selenium cannot find fields with number type

I have a problem getting Cucumber to search for fields with HTML5 type="number" . I'm not a big fan of how they look in the browser, but I have a few fields that need a numeric keypad on a mobile phone, and this seems to be the easiest way to get it. I use SimpleForm to create forms, and when I set :as => :text , everything works, but if I set :as => :number , the fields are not populated. I do not get any errors, the field simply does not fill out.

To be specific, when I have such a step:

 And I fill in "application_form_age" with "52" 

then this tag will not be filled:

 <input class=​"numeric integer required" id=​"application_form_age" min=​"0" name=​"application_form[age]​" size=​"50" step=​"1" type=​"number">​ 

but it works:

 <input class=​"string required" id=​"application_form_age" name=​"application_form[age]​" size=​"50" type=​"text">​ 

Also, this only happens in @javascript scripts. In situations where @javascript is not needed and the script does not launch the browser, this works fine too.

Versions of things:

 capybara (2.2.1) cucumber (1.3.14) selenium-webdriver (2.41.0) simple_form (2.1.1) webrat (0.7.3) Firefox 29.0 

I'm at a dead end. I tried pulling out a bunch of my JS and CSS application to find out if something that I am doing is working but no luck with that. I just fix this by forcing these fields to not have HTML5 type numbers in my test environment, but I don't want to live like that. Does anyone else see this? I could not find any references to it, which makes me seem like something that I am doing. But I could not understand it.

+1
ruby selenium cucumber capybara
source share
2 answers

First of all, I think you have confusion regarding these frameworks. Cucumber is the basis of BDD, which doesn’t automate browsers in any way, so this question has nothing to do with it (so I removed it from the question header).

It looks like you are using Capybara, which is the base of ATDD. You might be thinking about showing us the Capybara code that you use to diagnose your problem.

Under the hood, I assume that you are using Selenium WebDriver, I can confirm that Selenium works fine with <input type="number"> (Tested with Firefox 28, which supports one selenium-webdriver (2.41.0)).

 require 'selenium-webdriver' driver = Selenium::WebDriver.for :firefox DEMO_PAGE = <<-eos data:text/html, <input class=​"numeric integer required" id=​"application_form_age" min=​"0" name=​"application_form[age]​" size=​"50" step=​"1" type=​"number"> eos driver.get(DEMO_PAGE) driver.find_element(:tag_name, 'input').send_keys('25') 

So you might want to create a similar demo using Capybara to test this functionality.

If the demo works, we need to study your application more closely. Also, please raise a ticket for Capybara developers.

+1
source share

Well, I found that firefox has the ability to disable number input support: "dom.forms.number".

So, if you add the following lines to env.rb, entering the number will turn off and the tests will start working again.

 Capybara.register_driver :selenium do |app| profile = Selenium::WebDriver::Firefox::Profile.new profile["dom.forms.number"] = false Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile) end 
+2
source share

All Articles