How to find last matching element in capybara

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?

Best Answer

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

all('.delete').last