-
-
Save NaN1488/5240475 to your computer and use it in GitHub Desktop.
Update to work with chosen jquery plugin. If don't know the id of the select and find option by text rather than id.
Whitout using execute_script
This file contains 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
# Example: | |
# chosen_select 'select[name="projects"]', "ProjectA" | |
# | |
def chosen_select (css_select, option_text) | |
element_id = page.find(css_select)['id'] | |
page.driver.browser.mouse.down find("##{element_id}_chzn").native | |
within("##{element_id}_chzn") do | |
find(:xpath,"//li[text()=\"#{option_text}\"]").click | |
end | |
end |
Hi @sjtipton
It was tested in Capybara 1.1.1.
If you test it in Capybara 2.0, please let me know if it works.
Thanks!
For current version of capybara and choosen this working:
def chosen_select(css_selector, value)
page.evaluate_script(%{$('#{css_selector}').val('#{value}').trigger("chosen:updated");})
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this happen to work using Capybara 2.0?