title: Clicking an element inside repeater when another element equals specific input with protractor and jasmine
body: <p>My HTML structure is this:</p>
  
  <pre><code>&lt;li ng-repeat="m in members"&gt;
    &lt;div class="col-name"&gt;{{m.name}}&lt;/div&gt;
    &lt;div class="col-trash"&gt;
      &lt;div class="trash-button"&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>What I want to be able to do is using protractor, click on the trash when m.name equals a specific value.</p>
  
  <p>I've tried things like:</p>
  
  <pre><code>element.all(by.repeater('m in members')).count().then(function (number) {
    for (var i = 0 ; i &lt; number ; i++) {
      var result = element.all(by.repeater('m in members').row(i));
      result.get(0).element(by.binding('m.name')).getAttribute('value').then(function (name) {
          if (name == 'John') {
              result.get(0).element(by.className('trash-button')).click();
          };
        });
      };
    });
  </code></pre>
  
  <p>This seems like it should work, however, it seems like my function does not even run this.</p>
  
  <p>I've also looked into promises and filters though have not been successful with those either. Keep getting errors.</p>
  
  <pre><code>var array = element.all(by.repeater('m in members'));
  array.filter(function (guy) {
    guy.getText().then(function (text) {
      return text == 'John';
    })
  }).then(function (selected) {
    selected.element(by.className('trash-button')).click()
  }
  </code></pre>
  
  <p>All I would like to do is click on the corresponding trash when looking for a specific member list!</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p>EDIT: suggested I use xpath once I find the correct element, which is fine, the problem is I cannot get the filter function's promise to let me use element(by.xpath...)</p>
  
  <p>If I try:</p>
  
  <pre><code>var array = element.all(by.repeater('m in members'));
  array.filter(function (guy) {
    guy.getText().then(function (text) {
      return text == 'John';
    })
  }).then(function (selected) {
    selected.element(by.xpath('following-sibling::div/div')).click()
  }
  </code></pre>
  
  <p>I get the error:</p>
  
  <p>Failed: Object  has no method 'element'</p>
  
  <p>Figured it out. Following the Protractor filter guideline in the API reference and using alecxe's xpath recommendation, this code will click on any element you find after filtering it.</p>
  
  <pre><code>element.all(by.className('col-name')).filter(function (member, index) {
    return member.getText().then(function (text) {
      return member === 'John';
    });
  }).then( function (elements) {
    elements[0].element(by.xpath('following-sibling::div/div/')).click();
  });
  </code></pre>
  
  <p>You can change the xpath to select different stuff incase your HTML does not look like mine.</p>