Skip to content

Instantly share code, notes, and snippets.

@LolWalid
Last active December 10, 2015 10:18
Show Gist options
  • Save LolWalid/d2770dd3e5260ab877ac to your computer and use it in GitHub Desktop.
Save LolWalid/d2770dd3e5260ab877ac to your computer and use it in GitHub Desktop.

Use Capybara as genius

Purpose

Capybara uses selector css to find elements, we can do more than ".my-class" or "#my-id". XPath can be used to look for elements using different syntax, see above exemple.

Exemples

# Check <a> element with data-confirm attribute value ends with "?"
has_css?('a[data-confirm$="?"]')

# Find and select option #3 inside given select (options
find('select.my-select', match: :first).find(:xpath, 'option[3]').select_option  index start to 1)

Documentation

Documentation capybara

Documentation selector CSS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment