Skip to content

Commit

Permalink
Merge pull request goodwill#1 from chanthou/master
Browse files Browse the repository at this point in the history
update select2_multiple to find by xpath
  • Loading branch information
sanvuthy committed Sep 4, 2013
2 parents 08d55a0 + 3505c04 commit 8313905
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions gem/lib/capybara-select2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8313905

Please sign in to comment.