title: Is this a promise error? Selenium-webdriver test fails to find element after submitting a successful login
body: <p>I have written the following test, using selenium-webdriver. (There is also some setup for mocha and chai, but I haven't begun that work, yet.)</p>
  
  <p>My problem is that the test runs up to the point where I want it to wait for the page to load and to find an element with an ID of 'usergreeting', containing the text 'Welcome, ' + username. At that point, the test throws the error:
  <code>Uncaught NoSuchElementError: Unable to locate element: {"method":"id","selector":"usergreeting"}
  Command duration or timeout: 986 milliseconds</code></p>
  
  <p>However, I can see (watching Firefox go through the steps) that the page has loaded and is displaying the '#usergreeting' element. </p>
  
  <p>I don't know what I have done wrong, but I have obviously done SOMETHING wrong. Probably, I have not grasped the whole concept of promises. (See the section where I have written a <code>driver.wait()</code> statement.)</p>
  
  <p>Thanks for your help.</p>
  
  <pre><code>var assert = require('assert'),
    fs = require('fs'),
    webdriver = require('selenium-webdriver');
  
  require('mocha-as-promised')();
  var chai = require('chai');
  var chaiAsPromised = require('chai-as-promised');
  chai.use(chaiAsPromised);
  chai.should();
  
  describe('Login test', function() {
    var driver, configObj, username, pwd;
    this.timeout(6000);
    before(function(done) {
      driver = new webdriver
        .Builder()
        .usingServer('http://localhost:4444/wd/hub')
        .withCapabilities(
        {browserName: 'firefox'}
      )
        .build();
      configObj = require('../test/config.json');
      username = configObj.testuser;
      pwd = configObj.testpass;
      done();
    });
  
    it('User should be able to login', function(done) {
      driver.get('http://127.0.0.1:5207/Login.php');
      driver.findElement({id: 'UserNameEdit'}).sendKeys(username);
      driver.findElement({id: 'PasswordEdit'}).sendKeys(pwd);
      driver.findElement({id: 'LoginBtn'}).click();
      driver.wait(function() {
        return driver.findElement({id: 'usergreeting'}).innerText;
      }, 3000)
        .then(function(value) {
          assert.equal(value, 'Welcome, ' + username);
          done();
        });
      });
  });
  </code></pre>