Files
cypress/docs/source/api/commands/eq.md
T
2017-05-23 17:17:27 -04:00

2.2 KiB

title, comments, description
title comments description
eq true

Get a DOM element in an array of elements at the specific index.

Returns the new DOM element(s) found by the command.
Timeout cy.eq will retry for the duration of the defaultCommandTimeout

cy.eq( index )

Reduce the set of matched DOM elements to the one at the specified index.

cy.eq( indexFromEnd )

Providing a negative number indicates a position starting from the end of the set, rather than the beginning.

Options

Pass in an options object to change the default behavior of cy.eq.

cy.eq( index, options ) cy.eq( indexFromEnd, options )

Option Default Notes
log true whether to display command in command log
timeout defaultCommandTimeout Total time to retry getting the element

Index Usage

Find the 2nd element within the elements

<ul>
  <li>tabby</li>
  <li>siamese</li>
  <li>persian</li>
  <li>sphynx</li>
  <li>burmese</li>
</ul>
cy.get('li').eq(1).should('contain', 'siamese') // true

Index Form End Usage

Find the 2nd from the last element within the elements

<ul>
  <li>tabby</li>
  <li>siamese</li>
  <li>persian</li>
  <li>sphynx</li>
  <li>burmese</li>
</ul>
cy.get('li').eq(-2).should('contain', 'sphynx') // true

Command Log

Find the 4th li in the navigation

cy.get('.left-nav.nav').find('>li').eq(3)

The commands above will display in the command log as:

screen shot 2015-11-27 at 2 11 47 pm

When clicking on the eq command within the command log, the console outputs the following:

screen shot 2015-11-27 at 2 12 03 pm

See also