polarblau
polarblau

Reputation: 17744

Capybara: Link with HTML content not found

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!

Upvotes: 1

Views: 752

Answers (1)

gertas
gertas

Reputation: 17145

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.

Upvotes: 1

Related Questions