mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-18 22:28:38 -05:00
1.7 KiB
1.7 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| first | true |
Get the first DOM element within a set of DOM elements.
| Returns | the new DOM element(s) found by the command. |
| Timeout | cy.first will retry for the duration of the defaultCommandTimeout |
cy.first()
Reduce the set of matched DOM elements to the first in the set.
Options
Pass in an options object to change the default behavior of cy.first.
cy.first(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 first 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="one">Knick knack on my thumb</li>
cy.get("ul").first()
Command Log
Find the first input in the form
cy.get("form").find("input").first()
The commands above will display in the command log as:
When clicking on first within the command log, the console outputs the following: