Locating second, third, fourth,...eigth element in protractor using css locator Locating second, third, fourth,...eigth element in protractor using css locator selenium selenium

Locating second, third, fourth,...eigth element in protractor using css locator


There are no functions of those kind in protractor. Only available functions are first(), last() and get(). You can implement everything using these 3 functions on top of the ElementArrayFinder. Here's how -

element.all(by.css('h4.ng-binding')).first(); //get the first elementelement.all(by.css('h4.ng-binding')).get(0); //get the first element as get() function is a '0' based indexelement.all(by.css('h4.ng-binding')).get(1); //get the second elementelement.all(by.css('h4.ng-binding')).get(2); //get the third elementelement.all(by.css('h4.ng-binding')).last(); //get the last element

Hope it helps.


Now you can use functions like .second(); .third(); .fourth(); etc. - I developed a small package - https://github.com/Marketionist/protractor-numerator - that can be used with protractor to select second, third, fourth, etc. elements.


Use nth-child i.e.

element.all(by.css('h4.ng-binding:nth-child(2)'))...