Search code examples
cypressgetelementsbytagnamefindelement

How to find button element in a table grid


I am a newbie to cypress. I have a table of users and each row there is edit button. I want to find particular user by email and click on the edit button in that row. Can you please help me locating edit button for my Cypress test?

enter image description here


Solution

  • So you can do is something like this. First, get the parent row tr for the email and then inside that row, get the Edit button and click it.

    cy.contains('td', '[email protected]')
      .parent('tr')
      .children('td')
      .find('a')
      .click()