<select id="search_user_id_equals_any" name="search[user_id_equals_any]">
<option value="2">My Stuff</option>
<option value="-1,1,2,3,4,5">All Users</option>
<option value="3">The Cat</option>
</select>
所以,上面就是我想要验证的下拉列表
现在,当你点击某物时,它不会在你点击的任何选项中添加selected="selected",所以我不知道如何计算选择。
想法?
如何:
find_field(search_user_id_equals_any).value.should =~ /#{your_expected_value}/
?
您可以从Capybara源代码中看到value方法是如何工作的:
option = native.xpath(".//option[@selected='selected']").first || native.xpath(".//option").first
option[:value] || option.content if option
因此,按照设计,它将返回选项的值(如果存在),否则它将返回文本内容。请注意,如果没有选择任何选项,它将默认为第一个,就像一个真正的浏览器一样。
要获得你想要的行为,你可以这样做:
node = find_field('search_user_id_equals_any')
option = node.xpath(".//option[@selected='selected']").first || node.xpath(".//option").first
option_text = option.content