title: get element attribute value in Protractor
body: <p>I'm writing a Protractor test that has to wait for an element attribute to have a non-empty value and then I want to return that value to the caller function. This has proven to be more difficult to write than I expected!</p>
  
  <p>I am able to correctly schedule a <code>browser.wait()</code> command to wait for the element attribute to have a non-empty value and I have verified that this value is in fact what I am expecting to get inside the callback function, but for some reason, I am not able to return that value outside of the callback function and onto the rest of the test code.</p>
  
  <p>Here is how my code looks like:</p>
  
  <pre><code>function test() {
      var item = getItem();
      console.log(item);
  }
  
  function getItem() {
      var item;
      browser.wait(function() {
          return element(by.id('element-id')).getAttribute('attribute-name').then(function(value) {
              item = value;
              // console.log(item);
              return value !== '';
          });
      });
      return item;
  }
  </code></pre>
  
  <p>I can tell that the order of execution is not as I expect it to be, because when I uncomment the <code>console.log()</code> call inside the callback function, I see the expected value printed out. However, the same call in the <code>test()</code> function prints 'undefined'.</p>
  
  <p>What is going on here? What am I missing? How can I get the attribute value out of the callback function properly?</p>
  
  <p>I appreciate your help.</p>