2

I'm looking to get index position of matched element within repeater and would like to know how I can find.

List of books below

element.all(by.repeater('books'))

within those rows, some rows will have below element

element(by.css('[ng-click="download"]')

and I want to do following

  1. find element of download button (more than 1)
  2. get index position of first download button (so I can do other stuffs later with .get(3) for specific row)

So here what I have tried.

element.all(by.css('some-css')).first().element(by.tagName('tag-within-css')).get(index);
element.all(by.css('some-css')).get(index).element(by.tagName('tag-within-css'));

Finding Sub-Elements - Protractor locators guide

some error such as index not defined or no method of 'get'.

Thanks.

1 Answer 1

1

I think you don't need to operate using element positions/indexes inside the repeater. Instead, find download buttons and operate with the current row using context/element specific element searches by chaining element and element.all:

var books = element.all(by.repeater('books'));

var downloadButtons = books.all(by.css('[ng-click="download"]'));
var firstDownloadButton = downloadButtons.first();

// here is how you can, for example, get the next div element to the download button  
var nextElement = firstDownloadButton.element(by.xpath('following-sibling::div'));
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for reply @alecxe. I wanted to get index to check if checkbox of that row is checked or unchecked. By the way for, do those chaining works for array within array? Log is showing me that all from downloadButtons is undefined.
Ok @alecxe, I made minor adjustments and don't see the error but it's not clicking on the first download button. I removed downloadButtons and updated to var firstDownloadButton = bookingRequest.first().all(by.css('[ng-click="downloadAttachment(item)"]'));
@user2388556 looks like you've solved it, right? Thanks for the edit!
Yes @alecxe. After looking at documentation again and realised that I need to remove "element" from from downloadButtons and it clicks right on first element. Thanks again for the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.