Skip to content

Instantly share code, notes, and snippets.

@tonycoco
Created February 19, 2014 17:28
Show Gist options
  • Save tonycoco/9096945 to your computer and use it in GitHub Desktop.
Save tonycoco/9096945 to your computer and use it in GitHub Desktop.
Select2 Capybara Support File
# Useage: select2("value to select", from: "label text")
module Capybara
module Select2
def select2(value, options={})
select_name = options[:from]
select2_container = first("label", text: select_name).find(:xpath, "..").find(".select2-container")
select2_container.find(".select2-choice").click
find(:xpath, "//body").find(".select2-drop li", text: value).click
end
end
end
RSpec.configure do |config|
config.include Capybara::Select2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment