title: Make function wait before getting and returning DOM element
body: <p>Doing some headless testing using Mocha > Chai > PhantomJS.  Everything is setup and working, but I'm trying to fill a form with bad credentials, and then check to see that a DOM element is created.</p>
  
  <p>What I want to do is basically this:</p>
  
  <pre><code>it('should display error message string for bad credentials', function(done) {
      page.evaluate(function() {
          document.querySelector('input.form-input[type="text"]').value = 'foo@bar.com';
          document.querySelector('input.form-input[type="password"]').value = 'wrongpass';
          document.querySelector('input.form-action-b').click();
          return document.querySelector('div.status-oops p').innerText;
      }, function(result) {
          result.should.equal('Username and password do not match.');
          done();
      });
  });
  </code></pre>
  
  <p>But I'm getting: "Uncaught TypeError: Cannot read property 'should' of null"</p>
  
  <p>...because div.status-oops isn't there yet.  I get the same results in Chrome console, but if I then try to show the same text a few seconds later it works just fine.</p>
  
  <p>Any ideas how to delay the return?</p>