top of page

Cypress Tutorial

Get And Find Command

What Is Cypress Get Command ?

Cypress provides two essential methods get() and find() to find the web elements based on the locators.

​The get() method fetches one or more elements with the help of the selector passed as a parameter. It returns web element or a list of web elements based on the selector.
Syntax :
​cy.get(selector, args)

The second parameter args of the get() method is optional, we can skip it. There can be of three of types parameter as listed below :
  • log - type : boolean default value : true

  • timeout - default value : defaultCommandTimeout

  • withinSubject - default value : null

What Is Cypress Find Command ?

The find() method also fetches one or more web elements matching with the selector passed as an argument. But the difference between get() and find() methods is that the find() method always chains with other methods, such as get(). It cannot be used independently with the cy object. The find() command finds element within the scope of its parent command.
Syntax :
.find(selector, args)

The second parameter args of the find() method is optional, we can skip it. There can be of two of types parameter as listed below :
  • log - type : boolean default value : true

  • timeout - default value : defaultCommandTimeout

As we know that find() is always chained with other cypress command, usually with the get(), so below is its syntatical representation :

cy.get(parentSelector).find(childSelector)

Let's demonstrate it with an example code :


Run npx cypress open command, goto your spec, your output would look like this :


Refer next page Assertions In Cypress
bottom of page