1

当 you 时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'
4

1 回答 1

4

解决方案是:

select("customer", :from => "assignment[role_id]")
于 2012-11-27T23:47:58.440 回答