使用 Webrat 检查选择框是否具有某些选项
如何使用 Webrat 检查选择框是否具有列为选项的某些值?我目前有 field_named(field).value.should contains(value)
但仅传递第一个选定的值,而不传递未选定的值。如何检查未选择的选项是否存在?如何检查选择框中可用选项的数量?
我相信我需要类似于 field_named(field).element.search(".//option[@selected = 'selected']").inner_html.should =~ /#{value}/
只是我实际上并不关心所选择的内容 - 只关心存在的内容。
您还可以提供您的答案的来源吗?我发现关于使用 Webrat 超出基础知识的文档非常难以找到。
How do I use Webrat to check that a select box has certain values listed as options? I currently have field_named(field).value.should contain(value)
but that only passes for the first selected value and not for the unselected values. How do I check that the unselected options are present? And how do I check the number of options available in a select box?
I believe I need something akin to field_named(field).element.search(".//option[@selected = 'selected']").inner_html.should =~ /#{value}/
except that I don't actually care about what's selected - only what exists.
Can you also provide a source on where your answer comes from? I find documentation on using Webrat beyond the basics terribly difficult to find.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了类似的问题,我发现这很有用
,其中 value 是您要检查的文本,field 是选择框的 id。
希望它对你也有用!
I had similar problem, I found this useful
where value is the text you want to check and field is the id of the select box.
Hope it is useful to you too!