How to check if element exists using Cypress.io
问题 How to check if element is present or not, so that certain steps can be performed if element is present. Else certain different steps can be performed if element is not present. I tried something like below but it didn't work: Cypress.Commands.add('deleteSometheingFunction', () => { cy.get('body').then($body => { if ($body.find(selectors.ruleCard).length) { let count = 0; cy.get(selectors.ruleCard) .each(() => count++) .then(() => { while (count-- > 0) { cy.get('body') ... .... } }); } }); })