diff --git a/gem/lib/capybara-select2.rb b/gem/lib/capybara-select2.rb index abb0086..3fb981a 100644 --- a/gem/lib/capybara-select2.rb +++ b/gem/lib/capybara-select2.rb @@ -58,10 +58,14 @@ def select2_ajax(value, options = {}) end def select2_multiple(value, options = {}) - raise "Must pass a hash containing 'from'" if not options.is_a?(Hash) or not options.has_key?(:from) - select_name = options[:from] + raise "Must pass a hash containing 'from' or 'xpath'" unless options.is_a?(Hash) and [:from, :xpath].any? { |k| options.has_key? k } - select2_container=first("label", text: select_name).find(:xpath, '..').find(".select2-container") + if options.has_key? :xpath + select2_container = first(:xpath, options[:xpath]) + else + select_name = options[:from] + select2_container = first("label", text: select_name).find(:xpath, '..').find(".select2-container") + end [value].flatten.each do |value| select2_container.find(:xpath, "a[contains(concat(' ',normalize-space(@class),' '),' select2-choice ')] | ul[contains(concat(' ',normalize-space(@class),' '),' select2-choices ')]").click