admin管理员组文章数量:1356694
Is there a way to access the iterator index/key when looking for elements by repeater?
protractor.By.repeater("(id,cat) in pets")
In this case I'm looking to get access to "id" of the cat. The "id" is NOT one of the columns displayed as a value in the table, it is used for navigation as ng-click="goto('/pets/'+cat.id)"
. There is no binding in the HTML such as {{id}}
or {{cat.id}}
so doing the following:
ptor.findElements(protractor.By.repeater("(id,cat) in pets").column('cat.id'))
returns an empty element: []
I've also, unsuccessfully, tried doing something like:
ptor.findElement(protractor.By.repeater("(id,cat) in pets").row(0).column('cat.id'))
What is the correct way to access that specific index?
Here's the non-shortened syntax of the answer by Jmr:
ptor.findElements(protractor.By.repeater('(id, cat) in pets')).then(function (arr) { arr[0].evaluate('cat.id').then(function (id) { console.log(id); }); });
Is there a way to access the iterator index/key when looking for elements by repeater?
protractor.By.repeater("(id,cat) in pets")
In this case I'm looking to get access to "id" of the cat. The "id" is NOT one of the columns displayed as a value in the table, it is used for navigation as ng-click="goto('/pets/'+cat.id)"
. There is no binding in the HTML such as {{id}}
or {{cat.id}}
so doing the following:
ptor.findElements(protractor.By.repeater("(id,cat) in pets").column('cat.id'))
returns an empty element: []
I've also, unsuccessfully, tried doing something like:
ptor.findElement(protractor.By.repeater("(id,cat) in pets").row(0).column('cat.id'))
What is the correct way to access that specific index?
Here's the non-shortened syntax of the answer by Jmr:
ptor.findElements(protractor.By.repeater('(id, cat) in pets')).then(function (arr) { arr[0].evaluate('cat.id').then(function (id) { console.log(id); }); });Share Improve this question edited Nov 26, 2013 at 14:54 Nik asked Nov 22, 2013 at 20:45 NikNik 7,2026 gold badges39 silver badges53 bronze badges
1 Answer
Reset to default 10You're looking to evaluate something that's not on the page, so the 'row' and 'column' methods won't work. If you just use the repeater, you will get an array of all of the rows. You can then use the evaluate
mand to evaluate Angular expressions in the context of that element. For example (using shortened syntax),
element.all(by.repeater('(id, cat) in pets')).then(function(arr) {
arr[0].evaluate('cat.id'); // This is a promise which resolves to the id.
});
本文标签:
版权声明:本文标题:javascript - How to get iterator indexkey using protractor + angular? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743959202a2568705.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论