This code should work, I mocked it up and ran as expected.
$ie.radios.each_with_index do | radio, iIndex|
# Adjust index as radios are 1 indexed and arrays are zero indexed
iIndex = iIndex +1
if(($ie.radio(:index, iIndex).id == "ID_OTHER_OPTION_BUTTON"))
puts("Yes")
else
puts("NO")
end
end
Joe
On Jul 5, 5:51 am, Shlomit Gazit <[email protected]> wrote:
> Hello Joe,
> Thank you for your help.
>
> The results are as follow: I dont need radios 10-15 for my test.
>
> #-------------------------#
> # Attributes of radio 1
> #-------------------------#
> id: ID_LIMIT_OPTION_BUTTON
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: reqType
> type: radio
> value: Limit_1
> visible?: true
> inspect: #<Watir::Radio:0x3105f38 located=false how=:index what=1
> value=nil>
>
> #-------------------------#
> # Attributes of radio 2
> #-------------------------#
> id: ID_PAYMENT_OPTION_BUTTON
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: reqType
> type: radio
> value: Payment_3
> visible?: true
> inspect: #<Watir::Radio:0x32cc650 located=false how=:index what=2
> value=nil>
>
> #-------------------------#
> # Attributes of radio 3
> #-------------------------#
> id: ID_REGISTRATION_OPTION_BUTTON
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: reqType
> type: radio
> value: Registration_5
> visible?: true
> inspect: #<Watir::Radio:0x3184888 located=false how=:index what=3
> value=nil>
>
> #-------------------------#
> # Attributes of radio 4
> #-------------------------#
> id: ID_LABELLING_OPTION_BUTTON
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: reqType
> type: radio
> value: Labelling_7
> visible?: true
> inspect: #<Watir::Radio:0x30daa04 located=false how=:index what=4
> value=nil>
>
> #-------------------------#
> # Attributes of radio 5
> #-------------------------#
> id: ID_TESTING_OPTION_BUTTON
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: reqType
> type: radio
> value: Testing_8
> visible?: true
> inspect: #<Watir::Radio:0x31b6e8c located=false how=:index what=5
> value=nil>
>
> #-------------------------#
> # Attributes of radio 6
> #-------------------------#
> id: ID_TARGET_OPTION_BUTTON
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: reqType
> type: radio
> value: Target_2
> visible?: true
> inspect: #<Watir::Radio:0x30e0c4c located=false how=:index what=6
> value=nil>
>
> #-------------------------#
> # Attributes of radio 7
> #-------------------------#
> id: ID_REPORTING_OPTION_BUTTON
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: reqType
> type: radio
> value: Reporting_4
> visible?: true
> inspect: #<Watir::Radio:0x3192ec4 located=false how=:index what=7
> value=nil>
>
> #-------------------------#
> # Attributes of radio 8
> #-------------------------#
> id: ID_CERTIFICATION_OPTION_BUTTON
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: reqType
> type: radio
> value: Certification_9
> visible?: true
> inspect: #<Watir::Radio:0x2bc616c located=false how=:index what=8
> value=nil>
>
> #-------------------------#
> # Attributes of radio 9
> #-------------------------#
> id: ID_OTHER_OPTION_BUTTON
> alt:
> class: Watir::Radio
> enabled?: true
> getState: true
> innerText:
> isSet?: true
> name: reqType
> type: radio
> value: Other_10
> visible?: true
> inspect: #<Watir::Radio:0x311f7e4 located=false how=:index what=9
> value=nil>
>
> #-------------------------#
> # Attributes of radio 10
> #-------------------------#
> id: SinglereqDetailDeadLine_1
> alt:
> class: Watir::Radio
> enabled?: true
> getState: true
> innerText:
> isSet?: true
> name: radioRange_reqDetailDeadLine_1
> type: radio
> value: Single
> visible?: true
> inspect: #<Watir::Radio:0x31944b8 located=false how=:index what=10
> value=nil>
>
> #-------------------------#
> # Attributes of radio 11
> #-------------------------#
> id: RangereqDetailDeadLine_1
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: radioRange_reqDetailDeadLine_1
> type: radio
> value: Range
> visible?: true
> inspect: #<Watir::Radio:0x32a3020 located=false how=:index what=11
> value=nil>
>
> #-------------------------#
> # Attributes of radio 12
> #-------------------------#
> id: CustomreqDetailDeadLine_1
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: radioRange_reqDetailDeadLine_1
> type: radio
> value: Custom
> visible?: true
> inspect: #<Watir::Radio:0x30e1458 located=false how=:index what=12
> value=nil>
>
> #-------------------------#
> # Attributes of radio 13
> #-------------------------#
> id: SinglereqDetailExpiration_1
> alt:
> class: Watir::Radio
> enabled?: true
> getState: true
> innerText:
> isSet?: true
> name: radioRange_reqDetailExpiration_1
> type: radio
> value: Single
> visible?: true
> inspect: #<Watir::Radio:0x325ec90 located=false how=:index what=13
> value=nil>
>
> #-------------------------#
> # Attributes of radio 14
> #-------------------------#
> id: RangereqDetailExpiration_1
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: radioRange_reqDetailExpiration_1
> type: radio
> value: Range
> visible?: true
> inspect: #<Watir::Radio:0x3172bb0 located=false how=:index what=14
> value=nil>
>
> #-------------------------#
> # Attributes of radio 15
> #-------------------------#
> id: CustomreqDetailExpiration_1
> alt:
> class: Watir::Radio
> enabled?: true
> getState: false
> innerText:
> isSet?: false
> name: radioRange_reqDetailExpiration_1
> type: radio
> value: Custom
> visible?: true
> inspect: #<Watir::Radio:0x30ed3fc located=false how=:index what=15
> value=nil>
> E
> Finished in 153.359 seconds.
>
> On Jul 4, 7:17 am, joedio <[email protected]> wrote:
>
> > Shlomit,
>
> > Let's check the attributes of each of the radios.
> > Perhaps in actuality an attribute is NOT set
> > as one would expect it to be.
>
> > Run this code prior to the previous code block and look at the
> > results.
> > Feel free to add puts statements for any additional attributes you may
> > want to collect.
>
> > # Loop trough radios to display their attributes
> > $ie.radios.each_with_index do |radio, iIndex |
>
> > # Adjust index, as radios are 1 indexed, and arrays are
> > zero indexed
> > iIndex = iIndex +1
>
> > puts("\n#-------------------------#")
> > puts("# Attributes ofradio" + iIndex.to_s)
> > puts("#-------------------------#")
> > puts("id: " + $ie.radio(:index, iIndex).id.to_s)
> > puts("alt: " + $ie.radio(:index, iIndex).alt.to_s)
> > puts("class: " + $ie.radio(:index, iIndex).class.to_s)
> > puts("enabled?: " + $ie.radio(:index, iIndex).enabled?.to_s)
> > puts("getState: " + $ie.radio(:index, iIndex).getState.to_s)
> > puts("innerText: " + $ie.radio(:index, iIndex).innerText.to_s)
> > puts("isSet?: " + $ie.radio(:index, iIndex).isSet?.to_s)
> > puts("name: " + $ie.radio(:index, iIndex).name.to_s)
> > puts("type: " + $ie.radio(:index, iIndex).type.to_s)
> > puts("value: " + $ie.radio(:index, iIndex).value.to_s)
> > puts("visible?: " + $ie.radio(:index, iIndex).visible?.to_s)
> > puts("inspect: " + $ie.radio(:index, iIndex).inspect.to_s)
>
> > end
>
> > On Jul 4, 12:33 am, Shlomit Gazit <[email protected]> wrote:
>
> > > Joe,
>
> > > For example I was trying:
>
> > > $ie.radios.each do |radio|
> > > if($ie.radio(:id,"ID_OTHER_OPTION_BUTTON"))
> > > puts("yes")
>
> > > else
> > > puts("NO")
> > > end
> > > end
>
> > > The output was 15 yes instead of 1.
>
> > > On Jul 2, 9:05 am, joedio <[email protected]> wrote:
>
> > > > Schlomit,
>
> > > > Could you post the code you created from my example
> > > > so folks can look at it to try to determine why the conditional
> > > > is not working? Please include the output as well.
>
> > > > Thanks,
> > > > Joe
>
> > > > On Jul 2, 5:59 am, Željko Filipin <[email protected]>
> > > > wrote:
>
> > > > > 2010/7/2 Shlomit Gazit <[email protected]>
>
> > > > > > I want to create an array of the innerText (or something else) of
> > > > > > the
> > > > > > 9 out of 16 radios on the page.
> > > > > > Then I need to do something with every variable in this array.
>
> > > > > Then justiterateover allradiobuttons and create an array that contains
> > > > > just the ones you want:
>
> > > > > original_array = ["aa", "bb", "ab", "ba"]
>
> > > > > new_array = original_array.collect {|element| element if element =~
> > > > > /a/ }
> > > > > => ["aa", nil, "ab", "ba"]
>
> > > > > # compact removes nil elements
> > > > > new_array.compact
> > > > > => ["aa", "ab", "ba"]
>
> > > > > Željko
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
You received this message because you are subscribed to
http://groups.google.com/group/watir-general
To post: [email protected]
To unsubscribe: [email protected]