Radio buttons with watir-webdriver

531 views
Skip to first unread message

fabian....@gmail.com

unread,
Jun 17, 2013, 11:26:19 AM6/17/13
to watir-...@googlegroups.com
Guys,

I have this html :

<input type="radio" name="Server" value="1" onclick="displayHiddenText();setPageChanged(true);" id="Server_0">
<label for="Server_0">Yes</label>

which would be the right ruby code with watir-webdriver to set the radio button to Yes?
I've tried the examples at:


but I'm not being able to locate the element...

Thanks!
Fabian

Dan

unread,
Jun 17, 2013, 11:32:54 AM6/17/13
to watir-...@googlegroups.com
Please show us the code that you tried.

fabian....@gmail.com

unread,
Jun 17, 2013, 11:39:31 AM6/17/13
to watir-...@googlegroups.com
radio = browser.label(:for => 'Server_0').parent.radio.set

radio = browser.label(:name => 'Server').parent.radio.set

radio = browser.label(:text=> 'Server').parent.radio :value 'Yes'

etc

Dan

unread,
Jun 17, 2013, 11:54:04 AM6/17/13
to watir-...@googlegroups.com
I think you might be overcomplicating things, but if you want to work back up from the label you can do this:

b.label(:text => 'Yes').parent.radio.set

Otherwise you can just do this:
b.radio(:id => "Server_0").set
or
b.radio(:name => "Server").set

Fabian Arocena

unread,
Jun 17, 2013, 11:56:31 AM6/17/13
to watir-...@googlegroups.com
I thought b.radio was with watir, not watir-webdriver ...
I'm just following the examples n the webpage


--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
 
---
You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/3BHv_mq-d10/unsubscribe.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dan

unread,
Jun 17, 2013, 12:13:12 PM6/17/13
to watir-...@googlegroups.com, fabian...@gmail.com
If you want to follow the example on the page more closely it would be like this for your html:

>> radio = b.label(:text=> 'Yes').parent.radio :value => '1'
=> #<Watir::Radio:0x10ece2890 located=false selector={:type=>"radio", :value=>"1", :tag_name=>"input"}>
>> radio.set
=> nil

fabian....@gmail.com

unread,
Jun 17, 2013, 2:25:34 PM6/17/13
to watir-...@googlegroups.com, fabian...@gmail.com
Dan,

b.radio(:id => "Server_0").set

Worked like magic!

Thanks a million,
fabian
Reply all
Reply to author
Forward
0 new messages