title: Cypress: Can I prevent Cypress cy.get from failing if no elements are found?
body: <p>I am using Cypress <code>cy.get</code> to grab elements, but if there are none, my test is failing.
  I do not want it to fail. I want it to continue. The test is simply to list the items that are there, if any.</p>
  <pre><code>const listItemTitle = '[data-cy-component=list-item-title]';
  cy.get(listItemTitle).each(($el, index, $list) =&gt; {
    cy.wrap($el).then(($span) =&gt; {
      const spanText = $span.text();
      cy.log(`index: ` + index + ' ' + spanText);
    });
  });
  </code></pre>
  <p>I would have thought, if there are no elements there - that this code would still be ok, but not so. When I run it, I get this error: <code>CypressError: Timed out retrying: Expected to find element: '[data-cy-component=list-item-title]', but never found it.</code></p>
  <p>It works fine where elements are present. If no elements are found, I want to go on &amp; do a different test.</p>
  <p>Here is an experiment I tried:</p>
  <pre><code>let count: number = Cypress.$(listItemTitle).length;
  cy.log('before:' + count);
  cy.get(actionsBarActionsAdd).click();
  cy.get(singlePickerSearch).type('Assets' + '{enter}');
  cy.get(listItemCheckboxTitle)
    .first()
    .click();
  cy.toast({
    type: 'Success',
  });
  count = Cypress.$(listItemTitle).length;
  cy.log('after:' + count);
  cy.get(listItemTitle).each(($li, index, $lis) =&gt; {
    cy.log('interface no. ' + (index + 1) + ' of ' + $lis.length);
    cy.wrap($li).click();
  });
  </code></pre>
  <p>This was the outcome:</p>
  <pre><code>18 LOG        before:0
  19 GET       [data-cy-component-key=&quot;actions-add&quot;] input
  20 CLICK
  21 GET       [data-cy-component=single-picker-search] input
  22 TYPE      Assets{enter}
  23 GET       [data-cy-component=&quot;list-item-checkbox-title&quot;]
  24 FIRST
  25 CLICK
  26 GET       .iziToast    toast2
  27 ASSERT    expected [ &lt;div.iziToast.iziToast-opening.fadeInUp.iziToast-theme- 
  alloy.iziToast-color-green.iziToast-animateInside&gt;, 1 more... ] to have class iziToast-color-green
  28 LOG       after:0
  29 GET       [data-cy-component=list-item-title]
  30 LOG       interface no. 1 of 1
  </code></pre>
  <p>Conclusively shows that <code>Cypress.$(listItemTitle).length</code> does not count number of elements with selector: listItemTitle.</p>
  <p>Update:</p>
  <p>By putting a <code>cy.wait(1000)</code>; after the Add had been executed (in my experiment) - giving the DOM time to update - the new element was found. With more specific selectors, the wait is not required</p>