我有一个名为Club的模型,其中包含以下字段:
name (string)
creation (date)
然而,在我的表单中,我想在标签中显示Foundation Date,而不是显示创建,所以我在我的视图中有这个:
<div class="fields">
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :creation, 'Foundation date' %>
<%= f.date_select :creation %>
</div>
在我的测试中,我有以下内容:
scenario "User creates a club with a creation date" do
sign_in
visit new_club_path
fill_in 'Name', :with => 'Unió Esportiva'
select '1952/01/01', :from => 'Creation'
end
我得到了:
Capybara::ElementNotFound:
Unable to find select box "Creation"
呈现的HTML看起来像这样(对于选择框):
<select id="club_creation_1i" name="club[creation(1i)]">
...
</select>
<select id="club_creation_2i" name="club[creation(2i)]">
...
</select>
<select id="club_creation_3i" name="club[creation(3i)]">
...
</select>
我错过了什么?根据{{3}},我不需要单独选择每个框:
编辑:我不得不说我尝试使用'创建',因为在尝试使用“基准日期”标签时:
select '1952/01/01', :from => 'Foundation date'
我会得到完全相同的错误。但是,如果我单独选择框,例如:
select '1952', :from => 'club_creation_1i'
select '1', :from => 'club_creation_2i'
select '1', :from => 'club_creation_3i'
有效。
答案 0 :(得分:1)
http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions#select-instance_method
您可以通过它的名称,标签或ID选择一个选择框 - “创建”不是这些。