Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor - clicking a link in a list

Given a todo app that has a list of tasks: Walk the dog, Eat lunch, Go shopping. Each task has a 'complete' link.

Using Protractor, how do I click the complete link for the second task 'Eat lunch'? Preferably I'd like to do this without using indices in my test.

The html structure is like so...

<ul class="pending">
    <li ng-repeat="task in tasks">
        {{task.name}}
        <a href='#'>Complete</a>
    </li>
</ul>

This seems like a common situation so surely there has to be a simple solution that I'm overlooking. Thanks in advance

like image 289
BigCountry Avatar asked Dec 01 '13 20:12

BigCountry


Video Answer


1 Answers

element.all(by.repeater('task in tasks')).
  get(1).
  element(by.linkText('Complete')).
  click()

or

element.all(by.repeater('task in tasks')).
  get(1).
  $('a').
  click()
like image 52
Andres D Avatar answered Sep 29 '22 18:09

Andres D