title: Protractor get all select box (option) values
body: <p>In my tests I needed to check if all the expected values are present in a select box. It took me a while but I finally created this helper function:</p>
  
  <pre><code>function getSelectValues(elementFinder)
  {
    var defer = protractor.promise.defer(),
        promise = defer.promise;
  
    elementFinder.all(by.tagName('option')).then(function(elements)
    {
      var values = [],
          elemCount = elements.length,
          counter = 0;
  
      elements.forEach(function(element)
      {
        element.getAttribute('value').then(function(optionValue)
        {
          counter += 1;
          values.push(optionValue);
  
          if(counter === elemCount)
          {
            defer.fulfill(values);
          }
        });
      })
    });
  
    return promise;
  }
  </code></pre>
  
  <p>It works but looks really ugly to me. Is there a better way to do it?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>After another two hours of reading documentation I got my helper function reduced to:</p>
  
  <pre><code>getSelectValues: function(elementFinder)
  {
    return elementFinder.all(by.tagName('option')).map(function(elem, index)
    {
        return elem.getAttribute('value');
    });
  }
  
  profileType = element(by.model('regObj.profileType'));
  expect(getSelectValues(profileType)).toEqual(['', 'aa', 'bb', 'cc']);
  </code></pre>