without knowing what the exact html looks like. your question is a bit confusing in this. you state you want to iterate of a bunch of li's that exist in a ul => this is pretty easy to solve in a few ways one like above or: my_ul = browser.ul(<your ul locator here>) lis is a collection of li elements here the specs for it https://github.com/watir/watir/blob/f28fba39c14ce468981559a8d4610bc8c21bc711/spec/watirspec/elements/lis_spec.rb my_lis = my_ul.lis now that you have a collection of lis you can do something like my_lis.map(&:text) which is just short hand for each info here => http://www.brianstorti.com/understanding-ruby-idiom-map-with-symbol/
but your code examples you are searching for a div. its probably unlikely that your div will have lis that are not in a ul or ol, so they are probably just divs so you might want to just try and collect the divs inside of your div container, pretty much the same code except use div On Tue, Jan 3, 2017 at 6:13 PM, 'John Fitisoff' via Watir General < [email protected]> wrote: > Watir models everything in the DOM. So think something like this should > work > > b.uls.each do |ul| > ul.lis.each { |li| p li.text } > end > > > ------------------------------ > *From:* "[email protected]" <[email protected]> > *To:* Watir General <[email protected]> > *Sent:* Tuesday, January 3, 2017 2:59 PM > *Subject:* [wtr-general] iterating LI through elements > > Hello Folks, > > I am trying to find syntax for express the following. > > I want to iterate across LI elements in a UL (unordered list) > > I thought something like this would do it: > > all_li_elements = browser.div(:id => 'topLevelMenu0').li > > Maybe that's close? > > Then I was hoping to iterate though them search for one: > > all_li_elements.each { |e| puts e.text } > > Or perhaps I would use the list of LI elements in an RSpec expect > statement with an include matcher that specifies one in the list. > > I have used the following to see the text in an LI element: > > menu_li_element = browser.div(:id => 'topLevelMenu0').li(:text => "Open > New Document") > > which returns a single LI element. And, I find the text itself here: > > puts menu_li_element.text > "Open New Document" > > If you know of some useful references to this kind of stuff on the Net, > then please share the link or even a few keywords that might help me find > it. Perhaps there are methods better suited? > > -az > > > > > -- > -- > Before posting, please read http://watir.com/support. In short: search > before you ask, be nice. > > [email protected] > http://groups.google.com/group/watir-general > [email protected] > > --- > You received this message because you are subscribed to the Google Groups > "Watir General" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > > > -- > -- > Before posting, please read http://watir.com/support. In short: search > before you ask, be nice. > > [email protected] > http://groups.google.com/group/watir-general > [email protected] > > --- > You received this message because you are subscribed to the Google Groups > "Watir General" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. [email protected] http://groups.google.com/group/watir-general [email protected] --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
