-
-
Save castro-raul/1707725 to your computer and use it in GitHub Desktop.
Select item from chosen js select with Capybara and Selenium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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").native | |
| input.send_keys(item_text) | |
| find('ul.chzn-results').click | |
| input.send_key(:arrow_down, :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").native | |
| input.click | |
| input.send_keys(item_text) | |
| input.send_key(: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
On my system (rspec 2.0.9, capybara 1.1.2) I have to click the element first to focus it then enter keys, to make it work.