How to get iterator index/key when looking for elements by repeater?
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?
Is protractor.By.repeater("(id,cat) in pets") working for you?
I would try ptor.findElement(protractor.By.repeater("cat in pets").column('id'))
When I try "ptor.findElement(protractor.By.repeater("cat in pets").column('id'))" I get the following error:
Error: Unsupported locator strategy: findArrayOverride
To answer your question, 'protractor.By.repeater("(id,cat) in pets")' is working. I can pull out the information from columns used in the table by doing something like 'ptor.findElements(protractor.By.repeater("(id,cat) in pets").column('cat.name'))' since {{cat.name}} is present in the html structure of the table being displayed.
Currently, the By.repeater locator will find all children html elements that match the identifier and have the ng-binding class.
So if cat.id is not bound in any children nodes of the repeater, it will not be found by the locator.
As an alternative, you could parse through the ng-click attribute to grab the id:
var promisedCats = ptor.findElements(By.repeater("(id,cat) in pets");
promisedCats.then(function(cats){
for(int i = 0; i < cats.length; i++){
var catID = cats[0].getAttribute("ng-click").then(value){
return value.substring(13);
}
}
}
Something along these lines might work out for you.
Thanks for your quick reply, that is a very clever way of trying to get at it. The problem with that approach for me is that it will return the actual string "ecu.id" when accessing the ng-click attribute as opposing to the resolved id of say '1','5','12'.
var catID = cats[i].getAttribute("ng-click").then(function (value) { return value; })
returns: "goto('/pets/'+cat.id)"
I guess the thing to take away from this is that to get at the resolved cat.id it needs to be explicitly bound in one of the child nodes.
Looks like this was asked on stackOverflow as well, which is a great place for this kind of question. I answered there: http://stackoverflow.com/questions/20154148/how-to-get-iterator-index-key-using-protractor-angular