Something like this might work

Watir::Wait.until { @browser.links(:class, "more-matches").length >= 5 }

@browser.links(:class, "more-matches").each do |d|
    d.click
    p d.text
end

If you know what the expected number is you could probably just do 
d.when_present.click within the each block and skip the Wait statement.

For 3, you might try getting the collection that the parent element belongs to 
and then find the div you want by seeing if there's a matching link within the 
div:

link = b.link(:class, 'some link within the div you are targeting')
index = nil
b.divs(:class, 'foo').each_with_index do |dv, idx|
  index = idx if dv.links.include?(link)
end

Haven't ever needed to do this but it might work (this is just off the top of 
my head, maybe someone else has a better idea)




On Wednesday, November 13, 2013 2:55 AM, Anisha <[email protected]> 
wrote:
 
Hi,
I am using watir+ cucumber. I want to know how to make sure if the multiple 
elements belonging to a same class have been captured and will loop through.
I tried the code:
@browser.links(:class, "more-matches").each do |d|
    d.click
    p d.text
end
Issue faced: the step definition passes without performing any clicks on the 
element belonging to this class because somehow array is empty. Some of the 
results on the page have hidden links belonging to this class and some are 
visible. Can you please tell me how to handle this case.
1. How to wait for all the collection of elements to appear on the page? 
Basically how to add "wait_until_present" for a collection such as divs, links, 
etc.
2. How to identify to click on the visible elements in the loop of collection 
of elements?
3. How to collect the index of a parent element of a particular element in a 
collection?

-- 
-- 
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/groups/opt_out.

-- 
-- 
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/groups/opt_out.

Reply via email to