javascript - How to get div number/count in protractor test contained in element -
my test requires div count/number repeater assigned value with. tried search none of findings work.
array here in app.js
:
var rows = [a,b,c,d,e,f,g]; var items = [1,2,3,4,5,6,7];
html:
<div ng-repeat="row in rows"> <div ng-repeat = "item in items"> <span>{{item}}</span> </div> </div>
question: wanted div number item has value span element of 4 or any. how write in protractor test this.
what used below not work if value moves other div in next row:
var getnumber = element(by.css=".items").get(4)
what want :
var getnumber = element(by.css=".rows").get("something 1,2,3 or 4")
if want number - use map()
:
element.all(by.repeater("item in items")).map(function (elm, index) { return { value: elm.element(by.tagname("span")).gettext(), index: index } }).then(function (items) { (var i=0; < items.length; i++) { if (items[i].value === '4') { console.log(items[i].index); } } });
this print indexes of elements in repeater when span
text 4
.
if want filter repeaters span
text being equal 4
, use filter()
:
element.all(by.repeater("item in items")).filter(function (elm) { return elm.element(by.tagname("span")).gettext().then(function (text) { return text === "4"; }); });
Comments
Post a Comment