如何使用 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"
最佳答案
尝试使用 capybara rspec 匹配器 have_select(locator, options = {})相反:
#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
关于ruby-on-rails - 检查选择框是否具有 capybara 的某些选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5394799/