How to get the element before last?

2019-07-26 14:32发布

In Protractor, there is the .first() and .last() methods available on ElementArrayFinder:

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

elements.last();
elements.first();

But, how to get the element just before the last one (penultimate) without knowing how many elements are there in total?

1条回答
劫难
2楼-- · 2019-07-26 14:55

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

Negative indices are wrapped (i.e. -i means ith element from last)

elements.get(-2);  // the element before last
查看更多
登录 后发表回答