Capybara: Link with HTML content not found

Question!

Given a HTML structure like this

<a href="…"><strong>My Link</strong></a>

is not caught by Capybara through a cucumber step

When I follow "My Link"

using a default webstep

When /^(?:|I )follow "([^"]*)"$/ do |link|
  click_link(link)
end

while this works:

When I follow "<strong>My Link</strong>"

I haven't been using Capbybara for long, but I can see what causes the problem. So, on a more general level — what's the proper way to go about this? Surely this case has to be pretty common, right?

Any ideas and general musings about Cucumber abuse very welcome!

By : polarblau


Answers

I would move strong tag outside anchor tag or better use CSS for that.

Or you can assign id attribute to link and use it instead of content. This way is the best if your app supports multiple languages.

Otherwise you have to write some sort of xpath selector for such special case:

find(:xpath, "//a[contains(//text(), \"#{locator}\")]").click

Not tested, just an idea.

By : gertas


This video can help you solving your question :)
By: admin