title: How to check for an element that may not exist using Cypress
body: <p>I am writing a Cypress test to log in to a website. There are <code>username</code> and <code>password</code> fields and a <code>Submit</code> button. Mostly logins are straightforward, but sometimes a warning dialog appears first that has to be dismissed.</p>
  <p>I tried this:</p>
  <pre><code>cy.get('#login-username').type('username');
  cy.get('#login-password').type(`password{enter}`);
  
  // Check for a possible warning dialog and dismiss it
  if (cy.get('.warning')) {
    cy.get('#warn-dialog-submit').click();
  }
  </code></pre>
  <p>Which works fine, except that the test fails if the warning doesn't appear:</p>
  <pre><code>CypressError: Timed out retrying: Expected to find element: '.warning', but never found it.
  </code></pre>
  <p>Then I tried this, which fails because the warning doesn't appear fast enough, so <code>Cypress.$</code> doesn't find anything:</p>
  <pre><code>cy.get('#login-username').type('username');
  cy.get('#login-password').type(`password{enter}`);
  
  // Check for a possible warning dialog and dismiss it
  if (Cypress.$('.warning').length &gt; 0) {
    cy.get('#warn-dialog-submit').click();
  }
  </code></pre>
  <p>What is the correct way to check for the existence of an element? I need something like <code>cy.get()</code> that doesn't complain if the element can't be found.</p>