为什么Capybara不会在选择菜单中选择正确的项目?

时间:2012-11-27 23:29:47

标签: rspec capybara

当您save_and_open_page时,您可以看到我的表单包含:

<label class="select optional control-label" for="assignment_role_id">Role</label>
  <select class="select optional" id="assignment_role_id" name="assignment[role_id]">
    <option value="819">admin</option>
    <option value="820">customer</option>
</select>

为什么Capybara会在下拉菜单中选择正确的项目?我明白了:

Failure/Error: select("customer", :from => :Role)
     Capybara::ElementNotFound:
       cannot select option, no option with text 'customer' in select box 'Role'

...和...

Failure/Error: select("customer", :from => :assignment_role_id)
     Capybara::ElementNotFound:
       cannot select option, no option with text 'customer' in select box 'assignment_role_id'

...和...

Failure/Error: select("customer", :from => :role_id)
     Capybara::ElementNotFound:
       cannot select option, no option with text 'customer' in select box 'role_id'

1 个答案:

答案 0 :(得分:4)

解决方案是:

select("customer", :from => "assignment[role_id]")