title: How to check if element exists using Cypress.io
body: <p>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.</p>
  
  <p>I tried something like below but it didn't work:</p>
  
  <pre><code>Cypress.Commands.add('deleteSometheingFunction', () =&gt; {
    cy.get('body').then($body =&gt; {
      if ($body.find(selectors.ruleCard).length) {
        let count = 0;
        cy.get(selectors.ruleCard)
          .each(() =&gt; count++)
          .then(() =&gt; {
            while (count-- &gt; 0) {
              cy.get('body')
              // ...
              // ...
            }
          });
      }
    });
    });
  </code></pre>
  
  <p>I am looking for a simple solution, which can be incorporated with simple javascript
  <strong>if else</strong> block or <strong>then()</strong> section of the promise</p>
  
  <p>Something similar to Webdriver protocol's below implementions:</p>
  
  <ol>
  <li><code>driver.findElements(By.yourLocator).size() &gt; 0</code></li>
  <li>check for presenece of element in wait </li>
  </ol>
  
  <p>Kindly advise. Thanks</p>