本文介绍了检查选择框有与水豚的某些选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Capybara检查选择框是否包含作为选项列出的特定值?
它必须与Selenium ...兼容
How do I use Capybara to check that a select box has certain values listed as options?It has to be compatible with 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"
推荐答案
尝试使用capybara rspec matcher :
Try using the capybara rspec matcher have_select(locator, options = {}) instead:
#Find a select box by (label) name or id and assert the given text is selected
Then /^"([^"]*)" should be selected for "([^"]*)"$/ do |selected_text, dropdown|
expect(page).to have_select(dropdown, :selected => selected_text)
end
#Find a select box by (label) name or id and assert the expected option is present
Then /^"([^"]*)" should contain "([^"]*)"$/ do |dropdown, text|
expect(page).to have_select(dropdown, :options => [text])
end
这篇关于检查选择框有与水豚的某些选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!