title: What's the best way in Selenium WebDriver to wait for buttons to be enabled?
body: <p>I am creating an automated testing program with webdriverjs of an application where the 'Next' buttons are often disabled for a time, then enabled. The automation waits for the button to become enabled, then clicks the button.</p>
  
  <p>The class of a button in particular toggles from : 'btn btn-next disabled' to 'btn btn-next'</p>
  
  <p>I have come up with the following solution but wonder if there was a better way? </p>
  
  <pre><code>browser.wait(until.elementLocated(By.css('nav a[class="btn btn-next"]')),
  timeout, 'button still disabled after timeout').then(function() {
     browser.findElement(By.css('nav a[class="btn btn-next"]')).click();
  });
  </code></pre>
  
  <p>Which seems to do the trick. </p>
  
  <p>Originally my idea was to run function such as:</p>
  
  <pre><code>tryToClick = function(element){
    var classValue = element.getAttribute("class");
    isDisabled = classValue.search('disabled') !== -1 ? true : false;
    if(isDisabled){
      setTimeout(function () {
        tryToClick(element);
      }, 500);
    } else {
    element.click();
    }
  } 
  </code></pre>
  
  <p>However, methods such as search, split, contains, etc resulted in errors. Does anyone know why?</p>