Capybara: is it possible to get an attribute value from a css string?

If you are looking for an HTML element with a given value for a given attribute, you could do:

expect(page).to have_css('a[href="www"]')

Probably too late. But I also had the same problem and found the solution. It might help someone else.

page.find('div#drawer a')[:href]

The only way I have been able to do this is with jQuery.

href = page.evaluate_script("$('a.link_class').attr('href');")

Tags:

Capybara