Skip to content

Instantly share code, notes, and snippets.

@sirbrillig
Created March 6, 2013 04:47
Show Gist options
  • Save sirbrillig/5096794 to your computer and use it in GitHub Desktop.
Save sirbrillig/5096794 to your computer and use it in GitHub Desktop.
Capybara select2 fill_in helper (for eg: autocomplete).
def fill_in_select2(selector, options={})
page.find(:css, "#s2id_#{selector} a").click
page.find(:css, ".select2-search input.select2-input").set options[:with]
page.find(:css, ".select2-result-label").click # Choose the first result
end
@patreeceeo
Copy link

Thanks! Works beautifully except when there are multiple select2 elements on the page, then you need to scope the last two finds to within the active drop container, which has the ID "#select2-drop." At least with the version I'm using (3.5.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment