title: Custom wait condition in selenium-webdriver (javascript bindings) is not working
body: <p>I am having an issue with the selenium javascript bindings in defining a custom wait condition. I am writing a test case to test a button's functionality in which a button is disabled at first, but will eventually be enabled. The wait time between the states is very long (4 minutes), as there is a tutorial animation playing on page load, and the button is enabled when that is finished. </p>
  
  <p>I have tried using the until.elementIsEnabled condition on the button, but that does not work. So, I have been trying to get a custom condition working.</p>
  
  <p>According to the <a href="http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/until.html#elementLocated" rel="nofollow noreferrer">API documentation on until conditions</a>, a custom event can be coded as so:</p>
  
  <pre><code>driver.wait(function() {
      return driver.getTitle().then(function(title) {
          return title === 'webdriver - Google Search';
      });
   }, 1000);
  </code></pre>
  
  <p>From that example, I have this code to wait on the state to flip to true:</p>
  
  <pre><code>const locator = { id: "Button" };
  await driver.wait(until.elementLocated(locator));
  const button = await driver.findElement(locator);
  
  await driver.wait(async function () {
      const attr = await button.getAttribute("enabled");
      log.info(model.browser.type + " - " + "Polling attribute value: " + attr);
      return await attr === true;
  }, 400000);
  </code></pre>
  
  <p>From the logging I have there (which is the js-logging npm package), I see that selenium-webdriver is looping that code every millisecond, and the state does flip from false to true about 4 minutes into the loop, as expected. But the loop keeps going until it hits the timeout value of 400000ms, about two minutes after the status change on the variable.</p>
  
  <p>What am I missing here? </p>