Ruby 硒罐';找不到类型为number的字段
我在让Cucumber查找HTML5的字段时遇到问题Ruby 硒罐';找不到类型为number的字段,ruby,selenium,cucumber,capybara,Ruby,Selenium,Cucumber,Capybara,我在让Cucumber查找HTML5的字段时遇到问题type=“number”。我不太喜欢它们在浏览器中的外观,但我有几个字段需要手机上的数字键盘,这似乎是最简单的方法。我正在使用SimpleForm构建表单,当我设置:as=>:text时,一切都正常,但是如果我设置:as=>:number,字段就不会被填写。我没有得到任何错误,字段就是没有填充 具体来说,当我有这样一个步骤: And I fill in "application_form_age" with "52" 这样就不会填写此标签:
type=“number”
。我不太喜欢它们在浏览器中的外观,但我有几个字段需要手机上的数字键盘,这似乎是最简单的方法。我正在使用SimpleForm构建表单,当我设置:as=>:text
时,一切都正常,但是如果我设置:as=>:number
,字段就不会被填写。我没有得到任何错误,字段就是没有填充
具体来说,当我有这样一个步骤:
And I fill in "application_form_age" with "52"
这样就不会填写此标签:
<input class="numeric integer required" id="application_form_age" min="0" name="application_form[age]" size="50" step="1" type="number">
我被难住了。我试着拉出一堆我的应用程序JS和CSS,看看我正在做的事情是否破坏了它,但没有成功。我只是通过强制这些字段在我的测试环境中不包含HTML5类型的数字来修补它,但我不想这样生活。还有人看到了吗?我没有找到任何关于它的参考资料,这让它看起来像是我正在做的事情。但是我还没有弄明白。首先,我想你对那些框架有些困惑。Cucumber是一个BDD框架,它不会以任何方式自动化浏览器,所以这个问题与它无关(这就是为什么我从你的问题标题中删除了它) 看起来您正在使用Capybara,这是一个ATDD框架。您可能会考虑向我们展示您使用的水痘代码,以便诊断您的问题。 在幕后,我假设您使用Selenium WebDriver,我可以确认Selenium在
(使用Firefox 28进行测试,这是Selenium WebDriver(2.41.0)支持的一个功能)
需要“selenium webdriver”
driver=Selenium::WebDriver.for:firefox
DEMO_PAGE=好的,我发现firefox有一个选项可以禁用数字输入字段支持:“dom.forms.number”
因此,如果在env.rb中添加以下行,数字输入将被禁用,测试将再次工作
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
强制Firefox恢复到28版可以消除Selenium的问题。
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
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')
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