mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-18 22:28:38 -05:00
cbec33d637
- Updated some existing api docs to reflect structure changes - Added missing ‘pause’ command to sidebar and .yml english.
2.2 KiB
2.2 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| last | true |
Get the last DOM element within a set of DOM elements.
Syntax
.last()
.last(options)
Usage
.last() requires being chained off another cy command that yields a DOM element or set of DOM elements.
{% fa fa-check-circle green %} Valid Usage
cy.get('nav a').last() // Yield last link in nav
{% fa fa-exclamation-triangle red %} Invalid Usage
cy.last() // Errors, cannot be chained off 'cy'
cy.getCookies().last() // Errors, 'getCookies' does not yield DOM element
Arguments
{% fa fa-angle-right %} options (Object)
Pass in an options object to change the default behavior of .last.
| Option | Default | Notes |
|---|---|---|
log |
true |
whether to display command in command log |
timeout |
defaultCommandTimeout |
Total time to retry getting the element |
Yields
.last() yields the new DOM element found by the command.
Timeout
.last() will continue to look for the last element for the duration of the defaultCommandTimeout
Examples
Last element
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:
When clicking on last within the command log, the console outputs the following: