protractor icon indicating copy to clipboard operation
protractor copied to clipboard

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

Open penfold opened this issue 13 years ago • 9 comments

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.

penfold avatar Nov 14 '13 21:11 penfold

https://github.com/angular/protractor/blob/master/spec/basic/findelements_spec.js#L322

juliemr avatar Nov 14 '13 21:11 juliemr

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

penfold avatar Nov 14 '13 22:11 penfold

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] } }

penfold avatar Nov 14 '13 22:11 penfold

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()

juliemr avatar Nov 14 '13 22:11 juliemr

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.

penfold avatar Nov 14 '13 22:11 penfold

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

sakshisingla avatar Oct 15 '14 05:10 sakshisingla

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(); }) } });

DevTestOpsCoach avatar Dec 03 '14 13:12 DevTestOpsCoach

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()

hankduan avatar Dec 03 '14 19:12 hankduan

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);

adnanghaffar07 avatar Aug 31 '16 06:08 adnanghaffar07