Skip to content

Instantly share code, notes, and snippets.

@strukturedkaos
Forked from jkassemi/gist:3797001
Created September 28, 2012 19:17
Show Gist options
  • Save strukturedkaos/3801641 to your computer and use it in GitHub Desktop.
Save strukturedkaos/3801641 to your computer and use it in GitHub Desktop.
Select2.js capybara
def select2_select(text, options)
page.find("#s2id_#{options[:from]} a").click
page.all("ul.select2-results li").each do |e|
if e.text == text
e.click
return
end
end
end
@sirbrillig
Copy link

Nice! I wrote something similar: https://gist.github.com/sirbrillig/5096794

@argent-smith
Copy link

Doesn't work: it sees no li's in the DOM. Why could this be?

@andreierdoss
Copy link

This fork has worked for me: https://gist.github.com/andreierdoss/6313962

@fredwu
Copy link

fredwu commented Sep 6, 2013

A much simpler, cleaner version:

within 'label', :text => input do
  first(:xpath, './/..').set value
end

page.find('ul.select2-results li', text: value, visible: true).click()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment