ARTICLEViews: 19Share  Posted by - Anonymous

find specific elements in multiple elements in cypress

To find specific elements within multiple elements in Cypress, you can use the find() command in combination with cy.get().

For example, let's say you have multiple div elements with a class of "container", and within each of those containers, there are multiple button elements. If you want to find the second button within the second container, you can use the following code:

javascript


cy.get('.container').eq(1).find('button').eq(1)

Here's what's happening in this code:

  1. cy.get('.container') selects all elements with a class of "container".
  2. .eq(1) selects the second element from that list (since Cypress uses a zero-based index).
  3. .find('button') selects all button elements within that second container.
  4. .eq(1) selects the second button from that list.

Once you have selected the desired element, you can perform actions on it as usual. For example, to click on the second button within the second container, you could use:

javascript

cy.get('.container').eq(1).find('button').eq(1).click()



The video contains the details on how to identify multiple elements of same type and verify the text of each element. 1)Navigation ...

Working with Multiple Elements in Cypress | .each() | Cypress Testing

Cypress Automation Tutorial for beginners Multiple Element Interaction part 8

Visibility Of Multiple Elements Explained

Multiple elements and should('be.visible') assertion



Views -