开发者

cucumber: drop down should have item selected? How with xpath? Or maybe something else?

<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>

So, above is the drop down I want to verify something is selected in.

Now, when you click on something, it doesn't add the selected="selected" to whatever option you click, so I don't know how to figure out the selection.

ideas?


How about:

   find_field(search_user_id_equals_any).value.should =~ /#{your_expected_value}/

?


You can see from the Capybara source how the value method works:

option = native.xpath(".//option[@selected='selected']").first || native.xpath(".//option").first
option[:value] || option.content if option

So it looks like by design it will return the option's value, if present, and otherwise it will return the text content. And note how if no option is selected, it will default to the first, as a real browser would.

To get the behaviour you want, you could do something like this:

node = find_field('search_user_id_equals_any')
option = node.xpath(".//option[@selected='selected']").first || node.xpath(".//option").first
option_text = option.content
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜