Beautiful.  html.scan is exactly what I was after, that does the trick
immensely faster.

Thanks Jarmo.

- Jason

Jarmo Pertman wrote:
> 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 Wed, Feb 4, 2009 at 9:34 PM, Jason <freezingki...@gmail.com> 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 watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to