[Wtr-general] How to identify the nth instance of a div?
Jeff Fry
jeff.fry at gmail.com
Wed May 2 10:04:32 EDT 2007
On 5/2/07, Jason & Aneta <freezingkiwis at gmail.com> wrote:
>
> Hey all,
>
> Using the 1.5.1.1158 gem and enjoying the class support.
>
> Within my web page, I have the following, with 3 <div> nested inside
> the main "content" <div>.
>
> <div class="content">
> <div class="contentItem">
> </div>
> <div class="contentItem">
> </div>
> <div class="contentItem">
> </div>
> </div>
>
> How do I retrieve / act within the nth instance, i.e. the 1st, 2nd or
> 3rd of these "contentItem" divs?
Hi Jason,
divs (and many other elements) can be accessed by :index. For example:
ie.div(:index,2) # access the second div on the page
You can also identify elements using multiple attributes, for example :class
and :index :
ie.div(:class => 'contentItem', :index => 3) # access the 3rd div with a
class of 'contentItem'
...I believe that you can also as a variation go for the Nth div within a
div like so:
ie.div(:class, 'content').div(:index, 4) # access the div with
class='content', and then access the 4th div within it.
Take this last one with a grain of salt - I don't have a page to test it on
right now, but I believe that it works as I describe here.
Hope that helps,
Jeff
--
http://testingjeff.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20070502/78bf3b27/attachment.html
More information about the Wtr-general
mailing list