Created
October 14, 2013 04:11
-
-
Save onyxrev/6970632 to your computer and use it in GitHub Desktop.
Select2 search query and selection for Capybara
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
# usage: | |
# select2_choose("#some_element_id_with_select2_attached", :query => "Santa", :choose => "Santa Monica, California") | |
# NOTE: just make sure your 'choose' is unique in your results set | |
module Select2Helper | |
def select2_choose(id, options) | |
page.execute_script %Q{ | |
i = $('#s2id_#{id} .select2-offscreen'); | |
i.trigger('keydown').val('#{options[:query]}').trigger('keyup'); | |
} | |
within(".select2-drop-active") do | |
find(".select2-result-label", :text => options[:choose]).click | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting "Circular dependency detected while autoloading constant Admin::Select2Helper (RuntimeError)" with either of the solutions.