I am trying to get the src value of an HTML block. I specifically try to achieve this using at_css and not using XPath.
So far, all I get is either zero or an empty string.
This is HTML:
<div class="" id="imageProductContainer"> <a id="idLinkProductMainImage" href='URL'> <img id="productMainImage" src="SRC.jpg" alt="alt" title="A Title" align="left" class="product_image_productpage_main selectorgadget_selected"> </a> </div>
The code I have is:
item = page.doc.at_css("#productMainImage img").text.strip unless page.doc.at_css("#productMainImage img").nil? puts item #prints blank item = item["src"] puts item #prints blank
Where page.doc is the Nokogiri HTML element.
ruby ruby-on-rails ruby-on-rails-4 nokogiri
David sigley
source share