'Parsing Watir Results
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="" class="itemSpace">
<div class="itemContainer">
<a href="/en/Products/All/Tipless Chine" target="_blank" title="Click here to learn more about this product">
<div class="name itemName">Alpha<span style="display:none;">boat part, DELTAUPDATE</span></div>
<div class="saleDiscount" style="display:none;">25.575</div>
<div class="itemNo" style="display:none;">1711</div>
<div class="saleNote">SALE</div></a>
</div>
</div>
<div data-jplist-item="" class="itemSpace">
<div class="itemContainer">
<a href="/en/Products/All/Something" target="_blank" title="Click here to learn more about this product">
<div class="name itemName">Bravo<span style="display:none;">boat part</span></div>
<div class="saleDiscount" style="display:none;">300</div>
<div class="itemNo" style="display:none;">584</div>
<div class="saleNote">SALE</div></a>
</div>
</div>
<div data-jplist-item="" class="itemSpace">
<div class="itemContainer">
<a href="/en/Products/All/Something Else" target="_blank" title="Click here to learn more about this product">
<div class="name itemName">Charlie<span style="display:none;">boat part</span></div>
<div class="saleDiscount" style="display:none;">600</div>
<div class="itemNo" style="display:none;">413</div>
<div class="saleNote">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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
