title: How to check if an alert is open using nodejs webdriver (wd)
body: <p>I am struggling writing a test; in which I want to check if an alert exists, check its text if it does and accept it.</p>
  
  <p>I checked <a href="https://stackoverflow.com/questions/12639280/how-to-wait-for-an-alert-in-selenium-webdriver">How to wait for an alert in Selenium webdriver ?</a>, <a href="https://stackoverflow.com/questions/11467471/how-to-check-if-an-alert-exists-using-webdriver-with-java">How to check if an alert exists using WebDriver?</a> and <a href="https://stackoverflow.com/questions/7076758/selenium-2-4-0-how-to-check-for-presence-of-an-alert">selenium 2.4.0, how to check for presence of an alert</a>, but I fail to adapt it using <a href="https://github.com/admc/wd" rel="nofollow noreferrer">https://github.com/admc/wd</a></p>
  
  <p>I have written something along</p>
  
  <pre><code>browser.alertText(function (err, text) {
    if (text) {
      browser.acceptAlert(function () {
        // ...
      });
    }
  });
  </code></pre>
  
  <p>It works tremendously well when an alert is displayed, but <code>alertText</code> hangs when there is no alert window.</p>
  
  <p>How can I check if the alert exists before issuing <code>alertText</code>?</p>
  
  <p>Thanks for your help,</p>