Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

How to find last matching element in 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?

question from:https://stackoverflow.com/questions/18507392/how-to-find-last-matching-element-in-capybara

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

all('.delete').last

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...