Michael,

The scan method is part of the String class. If you look at the rdoc  
for the classes you can find some very useful methods.

The pickaxe book and other ruby tutorials are also helpful.

Alex

On 10 Feb 2009, at 16:14, Michael Hwee <michael_h...@yahoo.com> wrote:

>
>
> Very cool, Jarmo.
> If you don't mind, can you explain how to find such powerful neat  
> methods?
>
>
> That helps all of us.
>
> Thanks.
>
>
> ----- Original Message ----
> From: Jason <freezingki...@gmail.com>
> To: Watir General <watir-general@googlegroups.com>
> Sent: Monday, February 9, 2009 4:47:19 PM
> Subject: [wtr-general] Re: count the number of <div> elements  
> (without divs.find_all)
>
>
> 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