Skip to content

Instantly share code, notes, and snippets.

@hsuh
Created October 2, 2014 11:49
Show Gist options
  • Save hsuh/8405170e27f1130ce107 to your computer and use it in GitHub Desktop.
Save hsuh/8405170e27f1130ce107 to your computer and use it in GitHub Desktop.
capybara select by value
def select_by_value(id, value)
option_xpath = "//*[@id='#{id}']/option[@value='#{value}']"
option = find(:xpath, option_xpath).text
select(option, :from => id)
end
Save in a .rb file in spec/support/ (Optional)
Example use:
before do
select_by_value 'some_field_id', 'value'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment