What if you could pick exactly the right item on a page every time, without scrolling or guessing?
Why cy.first(), cy.last(), cy.eq() in Cypress? - Purpose & Use Cases
Imagine you have a long list of items on a webpage, and you want to check just the first, last, or a specific item manually by clicking and inspecting each one.
This means scrolling, clicking, and guessing if you picked the right element every time.
Manually finding elements is slow and tiring.
You might click the wrong item or miss changes in the list order.
It's easy to make mistakes and hard to repeat the exact steps consistently.
Using cy.first(), cy.last(), and cy.eq() lets you directly pick the first, last, or any specific item in a list automatically.
This saves time, reduces errors, and makes your tests clear and reliable.
cy.get('li').then(items => { const first = items[0]; // manual checks here })
cy.get('li').first().should('be.visible')
You can quickly and confidently test specific elements in a list without guessing or extra steps.
Testing a shopping cart where you want to check the first product's price, the last product's name, or the third product's quantity easily.
Manual element selection is slow and error-prone.
cy.first(), cy.last(), and cy.eq() pick elements directly and reliably.
This makes tests faster, clearer, and less buggy.