How to get an item to the last?

Protractor has the .first() and .last() methods available on ElementArrayFinder :

 var elements = element.all(by.css(".myclass")); elements.last(); elements.first(); 

But how to get an element immediately before the last (penultimate), without knowing how many total elements in total?

+1
source share
1 answer

You can use negative indexing to get elements from the end by index:

Negative indices are wrapped (i.e. -i means the item is from the latter)

 elements.get(-2); // the element before last 
+4
source

All Articles