Title: Tricky checkbox selection

When you installed Watir, the API doc was also installed.  This is straight from that doc:

 

checkbox(how, what=nil ,value=nil)

This is the main method for accessing a check box. Usually an <input type = checkbox> HTML tag.

 *  how   - symbol - how we access the check box , :index, :id, :name etc
 *  what  - string, int or re , what we are looking for,
 *  value - string - when  there are multiple objects with different value attributes, this can be used to find the correct object

returns a CheckBox object

Valid values for ‘how’ are

   :index      - find the item using the index in the container ( a container can be a document, a TableCell, a Span, a Div or a P
                 index is 1 based
   :name       - find the item using the name attribute
   :id         - find the item using the id attribute
   :beforeText - finds the item immediately before the specified text
   :afterText  - finds the item immediately after the specified text

Typical usage

   ie.checkbox(:id, 'send_email')                   # access the check box with an id of send_mail
   ie.checkbox(:name, 'send_copy')                  # access the check box with a name of send_copy
   ie.checkbox(:name, /n_/ )                        # access the first check box whose name matches n_
   ie.checkbox(:index, 2)                           # access the second check box on the page ( 1 based, so the first field is accessed with :index,1)

In many instances, checkboxes on an html page have the same name, but are identified by different values. An example is shown next.

 <input type = checkbox name = email_frequency value = 'daily' > Daily Email
 <input type = checkbox name = email_frequency value = 'Weekly'> Weekly Email
 <input type = checkbox name = email_frequency value = 'monthly'>Monthly Email

Watir can access these using the following:

   ie.checkbox(:id, 'day_to_send' , 'monday' )         # access the check box with an id of day_to_send and a value of monday
=> ie.checkbox(:name ,'email_frequency', 'weekly')     # access the check box with a name of email_frequency and a value of 'weekly'

 

There are some very good examples in the unittests located in the install directory for Watir.

 

Hope this helps,

 

--Mark

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paatsch, Bernd
Sent: Monday, January 23, 2006 10:23 AM
To: [email protected]
Subject: [Wtr-general] Tricky checkbox selection

 

Hello,

I have following html code and like to select the checkbox for "Test3". How can I do that?

<input  type="checkbox" name="Add_member[]" value="25"></td><td> Test1</td><td> Subscriber</td><td>208</td></tr>
<input  type="checkbox" name="Add_member[]" value="27"></td><td> Test2</td><td> Subscriber</td><td>208</td></tr>
<input  type="checkbox" name="Add_member[]" value="35"></td><td> Test3</td><td> Subscriber</td><td>208</td></tr>

 

Thanks.

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to