Closed penfold closed 10 years ago
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:
<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
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);
This seems to work fine..
But what is the correct usage of...
I can't seem to get a handle to the elements in each repeat.