Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Working with multiple matching element contains same attribute and value

Category: Cypress

Cypress provides various methods to work with the first element, last element, or element at a specific index, then you need to use the first(), last(), or eq() functions along with cy.get().

Get the first Element in Cypress
The function .first() is used to get the first element in a set of elements

For Example:
cy.get(‘.name-text-box’).first()

Get the last Element in Cypress
Similar to the above example, here .last() function is used to get the last element in a set of elements.
For Example:
cy.get(‘.mobile-text-box’).last()

Get the specific element by index in Cypress
To get a specific element in the set of elements, using eq() function along with cy.get(‘.msg-body’) as shown below
For Example:
cy.get(‘.text-box’).eq(2)

Leave a Reply

Your email address will not be published. Required fields are marked *