diff --git a/gem/lib/capybara-select2.rb b/gem/lib/capybara-select2.rb index cb6d1d2..d9cf8d1 100644 --- a/gem/lib/capybara-select2.rb +++ b/gem/lib/capybara-select2.rb @@ -8,12 +8,12 @@ def select2(value, options = {}) raise "Must pass a hash containing 'from' or 'xpath' or 'css'" unless options.is_a?(Hash) and [:from, :xpath, :css].any? { |k| options.has_key? k } if options.has_key? :xpath - select2_container = find(:xpath, options[:xpath]) + select2_container = find(:xpath, options[:xpath], match: :first) elsif options.has_key? :css - select2_container = find(:css, options[:css]) + select2_container = find(:css, options[:css], match: :first) else select_name = options[:from] - select2_container = find("label", text: select_name).find(:xpath, '..').find(".select2-container") + select2_container = find("label", text: select_name, match: :first).find(:xpath, '..').find(".select2-container") end # Open select2 field