Rails: How to use Capybara to test a link’s href-value without caring about the text?

To find a link based on just its href using capybara you could do

link = page.find(:css, 'a[href="actual link"]')

or if you’re looking to assert that the element exists

page.assert_selector(:css, 'a[href="actual link"]')

or – if using RSpec

expect(page).to have_selector(:css, 'a[href="actual link"]')

Since have link by default searches for substrings in the link text you can also do

expect(page).to have_link(nil, href: 'actual link')

or

page.assert_selector(:link, nil, href: 'actual link')

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)