检查选择框是否具有水豚的某些选项
如何使用 Capybara 检查选择框是否具有列为选项的某些值? 它必须与 Selenium 兼容...
这是我拥有的 HTML:
<select id="cars">
<option></option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
这就是我想要做的:
Then the "cars" field should contain the option "audi"
How do I use Capybara to check that a select box has certain values listed as options?
It has to be compatible with Selenium...
This is the HTML that I have:
<select id="cars">
<option></option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
This is what I want to do:
Then the "cars" field should contain the option "audi"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试使用水豚 rspec 匹配器 have_select(locator, options = {}) 相反:
Try using the capybara rspec matcher have_select(locator, options = {}) instead:
就其价值而言,我将其称为下拉菜单,而不是字段,所以我会写:
为了回答您的问题,这里是实现此功能的 RSpec 代码(未经测试):
如果您想测试该选项文本而不是值属性(这可能会使更具可读性场景),你可以这样写:
For what it's worth, I'd call it a drop-down menu, not a field, so I'd write:
To answer your question, here's the RSpec code to implement this (untested):
If you want to test for the option text instead of the value attribute (which might make for more readable scenarios), you could write:
作为替代解决方案,由于我不熟悉 xpaths,我这样做是为了解决类似的问题:
它非常简单,但花了我一些时间来弄清楚。
As an alternative solution, and as I'm not familiar with xpaths, I did this to solve a similar problem:
Its quite simple, but took me some time to figure out.
好吧,因为我在附近并看到了这个问题(并且今天进行了测试),所以决定发布我的方式:
Well, since i was around and saw the question (and been testing today) decided to post my way:
应该能解决问题
should do the trick