Protractor: Request example of element.all(by.repeater('xx in yy')).get(0)....

Created on 14 Nov 2013  路  9Comments  路  Source: angular/protractor

This seems to work fine..

expect(element.all(by.repeater('article in pagedArticles')).count()).toEqual(25);

But what is the correct usage of...

element.all(by.repeater('article in pagedArticles')).get(0)....

I can't seem to get a handle to the elements in each repeat.

question

All 9 comments

I've been looking at this but I only seem to be getting an 'empty' promise.

var first= element.all(by.repeater('article in pagedArticles')).get(0);
console.log(first);

gives:

{ then: [Function: then],
  cancel: [Function: cancel],
  isPending: [Function: isPending],
  errback: [Function: reject],
  driver_:
   { session_:
      { then: [Function: then],
        cancel: [Function: cancel],
        isPending: [Function: isPending] },
     executor_: { execute: [Function] },
     flow_:
      { events_: {},
        timer: [Object],
        history_: [],
        activeFrame_: [Object],
        schedulingFrame_: [Object],
        eventLoopId_: [Object] } },
  id_:
   { then: [Function: then],
     cancel: [Function: cancel],
     isPending: [Function: isPending] } }

That's because it's a WebElement. You'll need to use a method on it to get information out of it - like getText() or getAttribute()

first.getText().then(function (txt) {
   console.log(txt);
});

Outputs: Accountant

expect(first.getText()).toContain('Accountant');

Passes!

Thanks - I'm starting to get a better feel for this now.

Hi,

Could you please let me know, how can I access all the 8th elements in the following ng-repeat code and add them:

Account
            <div class="colB">Kilometer</div>
            <div class="colA">Net</div>
            <div class="colC">61</div>
            <div class="colA">Vat</div>
            <div class="colC">V2</div>
            <div class="colA">Row Total</div>
            <div class="colC">76</div>
        </div>
Account
            <div class="colB">Diners</div>
            <div class="colA">Net</div>
            <div class="colC">5</div>
            <div class="colA">Vat</div>
            <div class="colC">V2</div>
            <div class="colA">Row Total</div>
            <div class="colC">5</div>
        </div>
Account
            <div class="colB">Repairs</div>
            <div class="colA">Net</div>
            <div class="colC">6</div>
            <div class="colA">Vat</div>
            <div class="colC">V2</div>
            <div class="colA">Row Total</div>
            <div class="colC">7</div>
        </div>

So, I want to achieve: 76+5+7

Once I get the list, I want to perform action on it. Is it possible in Protractor? Say I want to do click operation on fifth element.

Doing somethng like:-

element.all(by.repeater('icon in homePageIcons')).then(function(icons) {
for (var i = 0; i < icons.length; ++i) {
icons[i].getText().then(function (txt) {
if(txt == 'Claims')
element(by.binding('Claims')).click(); //
//element(icons[i]).click();
})
}
});

I think you want something like this:

element.
  all(by.repeater('icon in homePageIcons')).
  filter(function(icon) {
    icon.getText().then(function(txt) {
      return txt == 'claims'
    })
  }).
  click()

You can get an indexed element from an array returned with

// Get the first element matching the .dfdf css selector
element.all(by.css('.dfdf')).get(0);

Was this page helpful?
0 / 5 - 0 ratings