Files
cypress/docs/source/api/commands/last.md
T
2017-05-19 12:01:36 -04:00

1.7 KiB

title, comments, description
title comments description
last true

Get the last DOM element within a set of DOM elements.

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

cy.last()

Reduce the set of matched DOM elements to the final one in the set.

Options

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

cy.last( options )

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

Usage

Get the last list item in a list.

<ul>
  <li class="one">Knick knack on my thumb</li>
  <li class="two">Knick knack on my shoe</li>
  <li class="three">Knick knack on my knee</li>
  <li class="four">Knick knack on my door</li>
</ul>
// returns <li class="four">Knick knack on my door</li>
cy.get("ul").last()

Command Log

Find the last button in the form

cy.get("form").find("button").last()

The commands above will display in the command log as:

screen shot 2015-11-29 at 12 33 52 pm

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

screen shot 2015-11-29 at 12 34 07 pm

Related