使用 Webrat 检查选择框是否具有某些选项

发布于 2024-09-17 21:27:04 字数 373 浏览 4 评论 0原文

如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饮湿 2024-09-24 21:27:05

我遇到了类似的问题,我发现这很有用

 Then /^"([^"]*)" should be seen within "([^"]*)"$/ do |value, field|
  find_by_id(field).text.should =~ /#{value}/ 
end

,其中 value 是您要检查的文本,field 是选择框的 id。

希望它对你也有用!

I had similar problem, I found this useful

 Then /^"([^"]*)" should be seen within "([^"]*)"$/ do |value, field|
  find_by_id(field).text.should =~ /#{value}/ 
end

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文