Going to Team Capybara's GitHub site, you can scroll down and select "Finding" and we can see a subset of all the Finders that Capybara has.
As you can see, there are many different types of Finders:
findby xpath [
In the first example we're using the Finder
find_field we're trying to find the field with the label "First Name," and checking for its value:
In the next one, we're trying to find the field, "by id," — and get the value from it:
For the next one, we're trying to find a link called, "Hello" — we're trying to find all visible links, and actually check, is this link actually visible?
find_link('Hello', :visible => :all).visible?
For the next one we're trying to find the button labeled, "Send" — and clicking on that. The first part, we're finding the button. For the second part, we're chaining an action to it, "Click."
Here we're trying to find the button which contains the value of "1234" — and clicking on that.
We can also search by xpath — we can search for the xpath value of the locator.
As you can see, with the Finders there's many different arguments and options you can use.
If you want to learn more about Finders, let's go to the Ruby doc of Capybara-Node-Finders.
If you scroll down, you can see that you have the method "find." With this method
find you can see arguments and options.
For options, you can wait, you can search for text, search for exact text, review text for whitespace characters, check to see if something's visible or not, search for id, class, et cetera.
find_button for locators, you can use an id, text id, value, title, text content, or the alt tag of an image.
find_link, and many others.
Here's some examples of the
You can do something like: find something and wait for five seconds, you can match the text, match the text exactly.
Let's say, we wanted to find only visible elements, which is the default way Capybara finds elements, we can explicitly say:
To find both, visible and invisible elements, we can either one of these:
If you wanted to find invisible elements, we can say:
In our next section, we're going to explore Matchers.
:::tip Quiz The quiz for this chapter can be found in section 3.2 :::