Created
March 6, 2013 04:47
-
-
Save sirbrillig/5096794 to your computer and use it in GitHub Desktop.
Capybara select2 fill_in helper (for eg: autocomplete).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Works beautifully except when there are multiple select2 elements on the page, then you need to scope the last two
find
s to within the active drop container, which has the ID "#select2-drop." At least with the version I'm using (3.5.0).