B Seven
B Seven

Reputation: 45941

How to test for the http ref in a link with Capybara

<div id="look_here">
  <a href="stackoverflow.com"><img src="xxxxxxxxxx.xxx"></a>
</div>

How would you test for this link in Capybara (and RSpec)?

The image is dynamically generated, so I just want to test by href.

Upvotes: 0

Views: 106

Answers (2)

B Seven
B Seven

Reputation: 45941

page.should have_selector "a[href='stackoverflow.com']"

See Section 5.8.1 Matching attributes and attribute values on http://www.w3.org/TR/CSS2/selector.html

Upvotes: 1

Oscar Del Ben
Oscar Del Ben

Reputation: 4515

This should work:

page.should have_xpath("//a[@href='stackoverflow.com']")

Upvotes: 1

Related Questions