title: Cypress: Finding number of elements without throwing error
body: <p>I need to find the number of elements present on a web page with a given locator(cy.get() or cy.xpath()). If the element is not present with the given locator, then it should not Fail the test.</p>
  
  <p>I have tried cy.get(), cy.find(), cy.xpath(): all of them fails the test in case the element is not found on web page.
  I have tried to use cy.get('body').find('loc').length;
  But it also fails the test.</p>
  
  <p>The below code works, but i am not able to use the value of x out side the loop. And scenario is as such that i cant put all of my code inside then().</p>
  
  <pre><code>let x = 0;
   cy.get("body").then(($body) =&gt; {
   x = $body.find("element").length;
   cy.log(`inside then: `,x);
  })
  cy.log(`outside then: `,x);
  </code></pre>
  
  <p>Expected:
  inside then: ,1
  outside then: ,1</p>
  
  <p>Actual:
  inside then: ,1
  outside then: ,0</p>