baarkerlounger
baarkerlounger

Reputation: 1226

Looping through child elements of a loop of parent elements

I have a set of divs that I'd like to loop through and within that I'd like to loop through child elements (several levels of nesting here).

If I do:

puts browser.div(:class => 'layout4').element(:class => 'event-info').text

then I correctly get the text of the child element that I want so I've tried to pluralize it like this:

browser.divs(:class => 'layout4').each do |event|
    browser.event.elements(:class => 'event-info') do |game|
        puts game.text
    end
end

but the inner loop there doesn't run at all.

Upvotes: 1

Views: 763

Answers (1)

SteveTurczyn
SteveTurczyn

Reputation: 36860

You forgot the 'each' on the inner loop

browser.divs(:class => 'layout4').each do |event|
    browser.event.elements(:class => 'event-info').each do |game|
        puts game.text
    end
end

Upvotes: 4

Related Questions