I have a link with a specific attribute on my page. Using Rspec + Capybara how can I check for the existence of this link?
<a href="#" id="text" data-content="This is a discrete bar chart.">Foo</a>
Does not work:
page.find(:css, 'a[data-content="This is a discrete bar chart."]')
Works:
page.find(:css, 'a#test')
Here are some different ways:
expect(page).to have_selector("a[href='#'][data-content='This is a discrete bar chart.']")
page.has_selector?("a[href='#'][data-content='This is a discrete bar chart.']")
page.find("a[href='#'][data-content='This is a discrete bar chart.']") # returns the node found
If you don't have access to page but have access to rendered, then
expect(Capybara.string(rendered)).to have_selector("a[href='#'][data-content='This is a discrete bar chart.']")
I have the same query, but the quotes are different.
find("a[data-method='delete']").click
and works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With