I'm using Watir
for getting data from published items, 12 on a single page. Structured as presented below, I am expecting 12 items to show up, much like how Nokogiri
parses results. I am using the :css way of obtaining it, or the direct browser.div, but the result isn't what I'm expecting.
How is this different than the way Nokogiri
grabs elements? I'm assuming Watir
accomplishes this in the same way. I then need to iterate through these items to get their data. I'm searching on the class itemContainer, which wraps around all 12 products on the page.
How can I get that array of divs?
## HTML
<div data-jplist-item="" >
<div >
<a href="/en/Products/All/Tipless Chine" target="_blank" title="Click here to learn more about this product">
<div >Alpha<span style="display:none;">boat part, DELTAUPDATE</span></div>
<div style="display:none;">25.575</div>
<div style="display:none;">1711</div>
<div >SALE</div></a>
</div>
</div>
<div data-jplist-item="" >
<div >
<a href="/en/Products/All/Something" target="_blank" title="Click here to learn more about this product">
<div >Bravo<span style="display:none;">boat part</span></div>
<div style="display:none;">300</div>
<div style="display:none;">584</div>
<div >SALE</div></a>
</div>
</div>
<div data-jplist-item="" >
<div >
<a href="/en/Products/All/Something Else" target="_blank" title="Click here to learn more about this product">
<div >Charlie<span style="display:none;">boat part</span></div>
<div style="display:none;">600</div>
<div style="display:none;">413</div>
<div >SALE</div></a>
</div>
</div>
## code
##### a is the browser
item = a.div(class: "itemContainer")
ap item.inspect
puts item.class
## result
"#<Watir::Div: located: false; {:class=>\"itemSpace\", :tag_name=>\"div\"}>"
Watir::Div
CodePudding user response:
I am not clear about your question. But I have printed link title and first division text here.
b.divs(class: 'itemContainer').each do |div|
p div.a.title
p div.a.div.text
end
Output
"Click here to learn more about this product"
"Alpha"
"Click here to learn more about this product"
"Bravo"
"Click here to learn more about this product"
"Charlie"