On Monday, July 18, 2016 at 2:05:06 PM UTC-7, Soori wrote:
>
> I have a scenario where there is a grid of elements with same class name. 
> I need to identify the element position using index.
>
> For example:
>
> <html>
> <body>
> <div class="grid"><p>text1</p></div>
> <div class="grid"><p>text3</p></div>
> <div class="grid"><p>text4</p></div>
> <div class="grid"><p>text23</p></div>
> <div class="grid"><p>text6</p></div>
> <div class="grid"><p>text88</p></div>
> <div class="grid"><p>text3</p></div>
> </body>
> </html>
>
>
> in the above example,  I need to find the index of the div for "text6". 
> Can you please help me how I can do this using watir?
>
> /S
>
>
If you know the text that will be in the div you want, why not identify by 
that?  why find the index using the class, and then use index, that's just 
more steps..

 my_div = b.div(class: 'grid', text: 'text6')    # (using newer style hash 
definition)
  or if you are oldschool..
 my_div = b.div(:class => 'grid', :text => 'text6')  # (using older 
hashrocket style hash definition) 

 Or to make it more generic (like if it was in a method) 

   search_text = 'text6'

   my_div = b.div(class: 'grid', text: search_text)

-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com

--- 
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 watir-general+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to