try something like:
puts $ie.html.scan(/<div.*class\s*=\s*"details"/i).size

pay attention to the " part. If you get 0 results, try it with '.
Also, it is possible that you have some with " and some with ' if
that's the case, then you should make this regular expression even
more abstract. Anyway, this should be quite fast if you get your
regexp correct.

On Feb 5, 5:47 pm, Paul Rogers <[email protected]> wrote:
> some one else asked a similar question a while back. I pointed them to
> some kind of solution, but I really cant remember what it was. It may
> have been something like taking the html, and using scan to get the
> div tags, and then using index to find the ones you are after.
>
> Paul
>
> On Wed, Feb 4, 2009 at 9:34 PM, Jason <[email protected]> wrote:
>
> > I've got anywhere from 1 to 10 <div> elements on my page with the same
> > class.
>
> > <div class="details">
>
> > I want a robust and quick way of determining how many, or iterating
> > through each of these divs.
>
> > divs.find_all does the job, but it's rather slow because it appears to
> > be iterating through EVERY <div> on my page (300+) and then attempting
> > to match these to the class, i.e.
>
> >   $ie.divs.find_all{|dv|/details/.match(dv.class_name)}.length
>
> > A little bit slow.
>
> > Alternatively I thought of using :index until I resulted in an error,
> > i.e.
>
> >   for i in 1..10 (until an error occurs)
> >      $ie.div(:class=>"details", :index=>i)
> >   end
>
> > But this seems a little messy.
>
> > Any better suggestions? Something simple I'm missing?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to [email protected]
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to