angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

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

Closed penfold closed 10 years ago

penfold commented 10 years ago

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.

juliemr commented 10 years ago

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

penfold commented 10 years ago

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

penfold commented 10 years ago
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] } }
juliemr commented 10 years ago

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

penfold commented 10 years ago
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.

sakshisingla commented 10 years ago

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
```
Kilometer
Net
61
Vat
V2
Row Total
76

<div class="row" ng-show="isExpanded" ng-repeat="row in rows">
                <div class="colA">Account</div>
        <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>

<div class="row" ng-show="isExpanded" ng-repeat="row in rows">
                <div class="colA">Account</div>
        <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
DevTestOpsCoach commented 9 years ago

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

hankduan commented 9 years ago

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()
adnanghaffar07 commented 8 years ago

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