Skip to content

Instantly share code, notes, and snippets.

@kamilhism
Forked from jaryl/chosen.rb
Created July 15, 2013 13:04
Show Gist options
  • Save kamilhism/5999773 to your computer and use it in GitHub Desktop.
Save kamilhism/5999773 to your computer and use it in GitHub Desktop.
def select_from_chosen(item_text, options)
field_id = find_field(options[:from])[:id]
within "##{field_id}_chzn" do
find('a.chzn-single').click
input = find("div.chzn-search input")
item_text.each_char do |char|
input.base.invoke('keypress', false, false, false, false, char.ord, nil);
end
find('ul.chzn-results').click
input.base.invoke('keypress', false, false, false, false, 40, nil); # down arrow
input.base.invoke('keypress', false, false, false, false, 13, nil); # return
within 'a.chzn-single' do
page.should have_content item_text
end
end
end
def select_from_multi_chosen(item_text, options)
field_id = find_field(options[:from])[:id]
within "##{field_id}_chzn" do
input = find("ul.chzn-choices input")
item_text.each_char do |char|
input.base.invoke('keypress', false, false, false, false, char.ord, nil);
end
input.base.invoke('keypress', false, false, false, false, 13, nil); # return
within 'ul.chzn-choices' do
page.should have_content item_text
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment