title: How to check if element is present using Selenium with Javascript?
body: <p>I am struggling with a simple test using Jest and Selenium. I am testing if an element is removed from DOM after clicking on it.</p>
  
  <p>I have tried this:</p>
  
  <pre><code> test('User removes button after clicking on it', async (done) =&gt; {
      await driver.navigate().to('myProjectUrl');
      await driver.wait(until.elementLocated(By.css('.wrapper')), 10000);
      await driver.findElement(By.id('buttonId')).click();
      const deleteButton = await driver.findElement(By.id('buttonId'));
      expect(deleteButton.isDisplayed()).not.toEqual(true);
      done();
  });
  </code></pre>
  
  <p>This seems to work. Test passes but I am getting:</p>
  
  <pre><code>StaleElementReferenceError: stale element reference: element is not attached to the page document
  </code></pre>
  
  <p>I have also tried this approach:</p>
  
  <pre><code>test('User removes button after clicking on it', async (done) =&gt; {
      await driver.navigate().to('myProjectUrl');
      await driver.wait(until.elementLocated(By.css('.wrapper')), 10000);
      await driver.findElement(By.id('buttonId')).click();
      const buttonOrMessage = await driver.wait(until.elementLocated(By.id('buttonId)), 300, 'missing_button');
      expect(buttonOrMessage).toEqual('missing_button');
      done();
  });
  </code></pre>
  
  <p>This approach is returning error, not message as expected.</p>
  
  <p>Any suggestions about what am I missing?
  Your help would be appreciated.</p>