The Capybara API: Interacting

Let's learn about capybara API, capybara anchor tags and matchers, and capybara form interacting methods.

Simulating user interaction with Capybara

After the test hits the project_path URL, we start to use Capybara methods to interact with the page elements. Specifically, we use the following:

  1. The fill_in method to place text in a text field
  2. The select method to choose an option from a select menu
  3. The click_on method to click on a button and submit a form

Capybara anchor tags

Capybara is quite flexible in how it allows us to specify the element we want to work with. We can specify any element by its DOM ID. Form elements can also be specified by their name attribute. The attached label’s text can specify form elements that have attached label tags. Elements like HTML anchor tags that have internal text can be specified via that text. An HTML anchor tag whose body is an image can be located by the image’s alt text attribute.

In other words, if we have an HTML snippet like this:

Get hands-on with 1400+ tech skills courses.