获取精选下拉列表值

时间:2016-09-21 11:37:17

标签: ruby-on-rails ruby-on-rails-4 rspec capybara

我正在尝试使用下一个代码获取下拉框的选定值:

scenario 'USA as default country' do
  expect(page).to have_select('report_country_code', selected: 'United States')
end

此字段的Html是下一个:

<select class="form-control country required" name="report[country_code]" id="report_country_code">
  <option value="US">United States</option>
  ....
  ....
  <option value="ZW">Zimbabwe</option>
</select>

错误如下:

expected to find select box "report_country_code" with "United States" selected but there were no matches. Also found "United States .... Zimbabwe", which matched the selector but not all filters.

1 个答案:

答案 0 :(得分:0)

有同样的问题。 <{3}}帮助了我

sudo apt-get install libxml2-dev