ManuKaracho
ManuKaracho

Reputation: 1218

Find element with specific child element with capybara

I am trying to write a test in which I need to find an a element, that contains a specific icon

<a href="#"><span class="icon icon-checkmark></span></a>

I tried using xpath but I am doing something wrong I guess..

save_button = find(:xpath, '//a[span(., "icon-checkmark")]')

What would be the proper way to find my save button?

Upvotes: 1

Views: 2040

Answers (2)

Thomas Walpole
Thomas Walpole

Reputation: 49870

You're close, except you need to specify that you're looking for a class name.

find(:xpath, ".//a[.//span[contains(concat(' ',@class,' '), ' icon-checkmark ')]]")

The concat and extra spaces are to make sure it matches the specific class name and not a substring of a different class name.

Upvotes: 4

Sandipan Pramanik
Sandipan Pramanik

Reputation: 348

Try this: '*//a/span[contains(@class,'icon-checkmark')]'

Upvotes: 1

Related Questions