If I've got some HTML like:
<div id='drawer'><ul><li><a href='www'>description</a>...
I've seen that I can get the value of href in Capybara with:
page.find('div#drawer a')['href']
But is there any way to retrieve that value if it's completely described as a css string? ie, trying to get the value for 'div#drawer a[href]'
I've tried with expressions like this:
page.find('div#drawer a[href]') => can't convert Capybara::Node::Element into String (TypeError)
page.find('div#drawer a[href]').value => can't convert nil into String (TypeError)
page.find('div#drawer a[href]').text => returns the text value of 'description'
I've got that css expression in an external config file, so would it be possible somehow to just use it directly and retrieve the value of the attribute in question?
Thank you...
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');")
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"]')
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