protractor icon indicating copy to clipboard operation
protractor copied to clipboard

by.repeater not working on angularjs example from website

Open vipper opened this issue 12 years ago • 8 comments

Hi,

I've used those angularjs examples form the website to give trainings and hands on. One of them is this below: li ng-repeat="todo in todos" input type="checkbox" ng-model="todo.done" span class="done-{{todo.done}}" {{todo.text}} /span /li and in this case when I try to use the follow command it doesn't work: element(by.repeater('todo in todos').row(0).column('todo.text'));

I'm facing this error: Error: No element found using locator: by.repeater("todo in todos").row("0").column("todo.text") Would I be doing something wrong?

vipper avatar Aug 20 '14 13:08 vipper

I took a peek at the ng-repeat documentation and it looks like you might want to edit the column locator.

Instead of .column('todo.text'), it might work with .column('{{todo.text}}'). If anything, to better solve the problem, I'd recommend breaking the locator apart to more easily find the issue, but then it would lose the "row and column" semantics.

It is kind of funny how some things just need the name of the variable while other things need it wrapped in curly braces. It looks like the pattern is that, if you're specifying both a row and a column, use the curlies. If only specifying a column, don't include curlies. Huh.

mitchhentges avatar Aug 20 '14 15:08 mitchhentges

I've already tried using {{todo.text}}, but doesn't work too.

2014-08-20 12:47 GMT-03:00 Mitchell Hentges [email protected]:

I took a peek at the ng-repeat documentation https://github.com/angular/protractor/blob/master/docs/api.md#protractorbyprototyperepeater and it looks like you might want to edit the column locator.

Instead of .column('todo.text'), it might work with .column('{{todo.text}}'). If anything, to better solve the problem, I'd recommend breaking the locator apart to more easily find the issue, but then it would lose the "row and column" semantics.

— Reply to this email directly or view it on GitHub https://github.com/angular/protractor/issues/1212#issuecomment-52797795.

vipper avatar Aug 20 '14 16:08 vipper

Can you try splitting it apart a little bit? E.g.

var allTodos = element.all(by.repeater('todo in todos')); //Gets all of the <li> elements
var myTodo = allTodos.get(0); //Refines down to only one <li> element
var myTodoDescription = myTodo.element(by.binding('todo.text')); //Gets description

mitchhentges avatar Aug 20 '14 16:08 mitchhentges

I also tried it. Looks like the binding is not working at all in this case.

2014-08-20 13:19 GMT-03:00 Mitchell Hentges [email protected]:

Can you try splitting it apart a little bit? E.g. var allTodos = element.all(by.repeater('todo in todos')); //Gets all of the elements var myTodo = allTodos.get(0); //Refines down to only one element var myTodoDescription = myTodo.element(by.binding('todo.text')); //Gets description

— Reply to this email directly or view it on GitHub https://github.com/angular/protractor/issues/1212#issuecomment-52802352.

vipper avatar Aug 20 '14 17:08 vipper

Hmm, I've done some research. Yes, the angularjs.org site still uses {{todo.text}} (I was beginning to wonder if they were using something else, judging by how this isn't working). I can verify this by checking the example's source.

Here's the relevant part:

  <h2>Todo</h2>
  <div ng-controller="TodoController">
    <span>{{remaining()}} of {{todos.length}} remaining</span>
    [ <a href="" ng-click="archive()">archive</a> ]
    <ul class="unstyled">
      <li ng-repeat="todo in todos">
        <input type="checkbox" ng-model="todo.done">
        <span class="done-{{todo.done}}">{{todo.text}}</span>
      </li>
    </ul>
    <form ng-submit="addTodo()">
      <input type="text" ng-model="todoText"  size="30"
             placeholder="add new todo here">
      <input class="btn-primary" type="submit" value="add">
    </form>
  </div>

I used the elementExplorer executable packaged with Protractor to jump through things as laid out in my above comment. Grabbing all repeaters worked perfectly. Obtaining just one <li> also worked properly. However, when getting a binding and checking it, isPresent() returned false.

var allTodos = element.all(by.repeater('todo in todos'));
var myTodo = allTodos.get(0);
var myTodoDescription = myTodo.element(by.binding('todo.text'));
myTodoDescription.isPresent(); //false

I also tried checking with getting the {{todo.done}} binding, but that also failed.

var myTodoDone = myTodo.element(by.binding('todo.done'));
myTodoDone.isPresent(); //false

Here's the strange part. I tried getting bindings that weren't under a repeater, and everything worked properly:

var myTodoController = element(by.css('div[ng-controller="TodoController"]'));
var allTodosLength = myTodoController.element(by.binding('todos.length'));
allTodosLength.isPresent(); //true

Consensus: Julie/Hank please halp ;) Getting things within ng-repeat by binding doesn't seem to work in this scenario

mitchhentges avatar Aug 20 '14 18:08 mitchhentges

This is a known bug: https://github.com/angular/protractor/issues/157

hankduan avatar Aug 20 '14 22:08 hankduan

:/ Neat! Thanks :)

mitchhentges avatar Aug 20 '14 22:08 mitchhentges

+1

askie avatar Jul 18 '16 10:07 askie