小编典典

选中选择框具有与水豚某些选项

selenium

如何使用水豚来检查选择框是否列出了某些值作为选项?它必须与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"

阅读 342

收藏
2020-06-26

共1个答案

小编典典

尝试使用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
2020-06-26