Capybara doesn't select option


I’ve build a filter in my application. Admin can select a category from a drop down select box and then only items (stakeholders) of that category are shown.

my markup looks like this:

<div class="filter">
  <%= form_tag admin_stakeholders_path, method: "get", id: "filter", class: "filter" do %>
    <%= label_tag "Field" %>
    <%= select "stakeholder", "field", options_for_select(options_for_fields, selected: @selected), {prompt: 'All'}, onchange: "$('#filter').submit();" %>
  <% end %>

I’ve written a spec for this:

describe "viewing the list of stakeholders" do

  let!(:field1) { Field.create!(name: "beleidsmakers") }
  let!(:field2) { Field.create!(name: "onderwijs") }

  let!(:stakeholder1) { Stakeholder.create!(name: "stakeholder1", field_id: }
  let!(:stakeholder2) { Stakeholder.create!(name: "stakeholder2", field_id: }
  let!(:stakeholder3) { Stakeholder.create!(name: "stakeholder3", field_id: }

before do
  user = User.create!(user_attributes)
  visit admin_stakeholders_path
it "shows the filtered stakeholders" do
  select "beleidsmakers", from: "stakeholder_field"
  expect(page).not_to have_text(

However, for some reason Capybara doesn’t select the option ‘beleidsmakers’, instead the default option ‘all’ is selected.

Is this because the selection is triggered by Javascript?

onchange: "$('#filter').submit();

How can I solve this?

thanks for your help,


Do you have Capybara configured to use a JavaScript driver such as Poltergeist or capybara-webkit?

Hi Andy,

no I haven’t.