Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find last matching element in capybara?

Tags:

capybara

I wanted to do find by class_name and return last element among all elements.

In jquery, we can write something like below but that don't seems to work in capybara

find(".delete:last")

If you are using webkit driver you can write something like -

find(".delete:last-child")

In capybara, you can get last element using below -

all(:css, ".delete").last

Is there any alternative to above?

like image 685
Sandip Ransing Avatar asked Aug 29 '13 09:08

Sandip Ransing


1 Answers

I had the same problem and ended up using this method in Capybara 2.4

all('.delete').last
like image 84
Arctodus Avatar answered Sep 30 '22 15:09

Arctodus