如何使用Rails 3中的Capybara从选择框中选择日期? [英] How to select date from a select box using Capybara in Rails 3?
问题描述
select Date.today,from from => '出生日期'
但规范失败,我收到错误:
失败/错误:选择Date.today,from from =>'出生日期'
NoMethodError:
undefined方法`to_xpath'为星期一,2011年7月18日:日期
如何解决?
PS在视图文件中,我使用simple_form_for标签,选择框由代码生成:
f.input:date_of_birth
您需要在html的选择菜单中指定确切的值。所以如果你的选择有像2011/01/01的值,那么你需要写:
select'2011/01 / 01',:from => '出生日期'
您的代码失败,因为您传递日期对象。
I'm writing a spec for a controller in Rails 3 project using RSpec and Capybara, and I want to select current date from a select box. I tried:
select Date.today, :from => 'Date of birth'
but the spec fails and I get error:
Failure/Error: select Date.today, :from => 'Date of birth' NoMethodError: undefined method `to_xpath' for Mon, 18 Jul 2011:Date
How to fix it?
P.S. In view file I use simple_form_for tag and the select box is generated by code:
f.input :date_of_birth
You need to specify the exact value as it's in the select menu in html. So if your select has values like "2011/01/01" then you need to write:
select '2011/01/01', :from => 'Date of birth'
Your code fails because you pass a date object.
这篇关于如何使用Rails 3中的Capybara从选择框中选择日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!