'Protractor locator for multiple elements with same formControlName

I am trying to locate an element which is text field, and provided with formControlName. But the formControlName is same for all the input fields that comes after clicking on the add button. So how can i insert into the nth text field with same formControlName? how to fetch the total count of elements with same formControlName?

I am new to this automation using protractor, please do help.

We are currently using cucumber framework with protractor javascript.



Solution 1:[1]

To fetch the total count of elements with same formcontrolname can be achieved by using

var count = await element.all(by.xpath("ElementXpath")).count();

If you want to input to nth element it can be done by providing the number with the locator for example,

//input[name='subject'][3]

here,it will select the 3rd input with name subject from top to bottom order

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sarath