Skip to content

Instantly share code, notes, and snippets.

@semipermeable
Created October 17, 2011 22:27
Show Gist options
  • Save semipermeable/1294040 to your computer and use it in GitHub Desktop.
Save semipermeable/1294040 to your computer and use it in GitHub Desktop.
Replacement "When I select" step for old capybara and new selenium-webdriver
# features/step_definitions/web_steps.rb
# This replacement step works around an incompatibility between capybara-0.3.9 (or thereabouts) and selenium-webdriver >=2.5.0.
When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
with_scope(selector) do
# See https://github.com/jnicklas/capybara/issues/88
# page.find_by_id(field).select(value)
if Capybara.current_session.mode == :selenium
select_node = page.find_by_id(field)
select_node.click
select_node.node.find_elements( :tag_name => "option" ).find do |option|
option.text == value
end.click
else
select(value, :from => field)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment