Thunfische
Thunfische

Reputation: 1167

Accessing the first column of first row of a table in Protractor

               <tr ng-repeat="a in people">
                    <td>
                        {{a.firstname}}
                    </td>
                    <td>
                        {{a.lastname}}
                    </td>
                    <td>
                        {{a.email}}
                    </td>
                </tr>

protractor code

   var firstname = element.all(by.repeater('a in people'));          
   expect(firstname.get(0).getText()).toEqual('george');

This returns the entire first row. How do I get the first column? Thanks

Upvotes: 2

Views: 1096

Answers (2)

Maulik
Maulik

Reputation: 11

Technically when ng-repeat executes, it will repeat the element into the dom, In your case < tr ng-repeat='a in people'> tag will be repeated. So element.all(by.repeater('a in people')) results in multiple rows, hence get(0) method will return first row.

We can use following code to get first column of the first row.

      var firstname = element(by.repeater('a in people').row(0).column('a.firstname')); 
      expect(firstname.getText()).toEqual('xyz');       

Upvotes: 1

Oleksii
Oleksii

Reputation: 1643

You could get it like this:

 var all = element.all(by.repeater('a in people')).all(by.css('td'));          
 expect(all.get(0).getText()).toEqual('george');

element.all(by.repeater('a in people')); it will find just one element. If on the page will be two elements with this repeater text it will find two. But you need make search by td also.

Upvotes: 2

Related Questions