bmw0128
bmw0128

Reputation: 13698

Protractor getText of WebElement in repeater array

In an html page I have:

<ul class="phones">
              <li ng-repeat="phone in phones | filter:query | orderBy: orderProp">
                {{phone.name}} - {{phone.age}}
                <p>{{phone.snippet}}</p>
              </li>
            </ul>

In an e2e test I have (is returning two elements in the array):

            var result= ptor.findElements(protractor.By.repeater('phone in phones').column('phone.name'));

            result.then(function(arr) {
                arr[0].getText().then(function(text) {
                    console.log("*** 1: "+ text);
                });

                arr[1].getText().then(function(text) {
                    console.log("*** 2: "+ text);
                })
            });

The console is printing all three columns, phone.name, phone.age, and phone.snippet. Why is the selector not just returning phone.name?

Its actually returning whatever I have in the list "li", plain text or a binding.

Upvotes: 6

Views: 10371

Answers (1)

Heikki
Heikki

Reputation: 15417

The example tries to locate elements with the strategy below (column part is fixed as per comments):

protractor.By.repeater('phone in phones').column('name')

Repeater part matches the li element and then goes to find element(s) with phone.name binding. It's wrapping element happens to be the same li.

Changing column part to .column('snippet') returns p elements because phone.snippet binding is found inside of those.

Relevant docs/examples here: https://github.com/angular/protractor/blob/master/docs/getting-started.md#writing-tests

Upvotes: 3

Related Questions