user3779502
user3779502

Reputation: 173

Getting Text from Repeater in Protractor

<li ng-repeat="menu in menulist" ng-class="isActive(menu.type, menu.complete)" ng-click="setTopNav(menu.type, menu.complete)">{{menu.label}}</li>

Is the code for our menu. I'm trying to detect an array of the label names with

this.menuNav = element.all(by.repeater('menu in menulist').column('label'));

I bring that page object in a test and try to use the assertion

expect(navHeader.menuNav[1].getText()).toEqual('Label 2');

And I get this error

TypeError: Cannot call method 'getText' of undefined

What am I doing wrong?

Upvotes: 2

Views: 923

Answers (1)

Nguyen Vu Hoang
Nguyen Vu Hoang

Reputation: 1570

Protractor returns a promise, you need to change your code into

element.all(by.repeater('menu in menulist').column('label')).then(function(elems) {
    expect(elems[1].getText()).toEqual('Label 2');
});

Upvotes: 4

Related Questions