title: WatiN seems to not find JavaScript alert
body: <p>I have a web application that, under some conditions, pop up JavaScript alert()s that I need to react to in a WatiN test. Google pointed me at <a href="http://tmichealson.blogspot.com/2007/01/handling-alerts-in-watin.html" rel="nofollow">Handling alerts in WATIN</a> from way back in 2007 that seemed promising, and I adapted the example code in that post into the following (anonymized):</p>
  
  <pre><code>    private void MyAssert(IE browser, WatinHelper helper)
      {
          AlertDialogHandler alertDialogHandler = new AlertDialogHandler();
  
          using (new UseDialogOnce(browser.DialogWatcher, alertDialogHandler))
          {
              // DoWrong() causes a JavaScript alert(); false means use nowait.
              DoWrong(helper, false);
  
              alertDialogHandler.WaitUntilExists(10 /*seconds*/);
  
              if (!alertDialogHandler.Exists())
              {
                  Assert.Fail("No JavaScript alert when it should have been there");
              }
  
              alertDialogHandler.OKButton.Click();
          }
  
          SecondAssert(browser);
      }
  </code></pre>
  
  <p>However, while the alert is displayed virtually instantaneously (as it is supposed to) when DoWrong() is called, the call to alertDialogHandler.WaitUntilExists() eventually fails with a <code>WatiNException: Dialog not available within 10 seconds..</code>. The only problem was that I could see that the dialog most definitely was up on the screen.</p>
  
  <p>I'm probably missing something simple; can someone point me in the right direction please?</p>
  
  <p>I have also tried the following two variants, and some variations of them, with no luck; I keep getting the same error.</p>
  
  <pre><code>        AlertDialogHandler alertDialogHandler = new AlertDialogHandler();
  
          DoWrong(helper, false);
  
          System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
          stopwatch.Start();
  
          do
          {
          }
          while (!alertDialogHandler.Exists() &amp;&amp; stopwatch.Elapsed.TotalMilliseconds &lt; 3000);
  
          Assert.IsTrue(alertDialogHandler.Exists(), "No JavaScript alert when it should have been there");
  
          alertDialogHandler.OKButton.Click();
          SecondAssert(browser);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>        AlertDialogHandler alertDialogHandler = new AlertDialogHandler();
          browser.DialogWatcher.Add(alertDialogHandler);
          DoWrong(helper, false);
          alertDialogHandler.WaitUntilExists();
          alertDialogHandler.OKButton.Click();
          browser.WaitForComplete();
          Assert.IsFalse(alertDialogHandler.Exists());
          SecondAssert(browser);
  </code></pre>
  
  <p>Yes, I know that code is getting a bit ugly, but right now I'm mostly trying to get it to work at all. If it sits for a few seconds cooking the CPU at 100% utilization because of the tight loop in my second attempt, but only does what I need it to (plain and simple, dismiss that <em>alert()</em>), it's OK.</p>