Forum Discussion

salley's avatar
salley
Frequent Contributor
7 years ago

Click on a specific radio button in a table

Hi,

I've a dynamic  table tha have many radiobuttons and i need to click on a specific item. is there a way to click on a item by index number.

below script clicks the last item from from the list, not sure how do i click on specific item, 

 

Set updateAddWindow=mypage.panelPnlupdate
If updateAddWindow.Exists And updateAddWindow.Visible=True Then
Log.Message "Address Update Window Found"
Set objRadBtns=updateAddWindow.FindChild("ObjectType","RadioButton",20)
If UBound(objRadBtn)>=0 Then
    For i =0 To LBound(objRadBtn)
       Set RadBtn=objRadBtn(i)
       RadBtn.Click
  Next
End If

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Couple of minor notes on the code:

     

    1) Detecting exists is best if you do the assignment using WaitAliasChild

     

    Set updateAddWindow=mypage.WaitAliasChild('panelPnlupdate', 5000)

     

    2) If you're actually expecting an array, you should use FindAllChildren instead of FindChild.

     

    Now... that all said, if you want to click on a specific radio button, the For loop is not the way to do it, at least not as you have it.  It will click on ALL the radio buttons.

    So... what I would do....  I'm not sure how your developers set up your radio buttons but many times the radio button caption will be part of the component itself.  So, I would do just a "FindChild" to look for the radio button but, instead of just looking for ObjectType alone, I'd add a second property in the find to look for the desired caption.

     

     

    Dim PropArray, ValueArray
    PropArray = Array("ObjectType", "Caption")
    ValueArray = Array("RadioButton", "MyCaption")
    Set objRadBtn = updateAddWindow.FindChild(PropArray, ValueArray, 20)

    This will allow you to find the specific desired radio button.  You can replace those property/value pairs with whatever you need to find the button you're looking for and then click on that button, no for-loop needed.

     

     

    • salley's avatar
      salley
      Frequent Contributor

      Hi,

      I've used your method and works fine on a static radiobutton where caption is the same, but my case that caption changes based on user input. but the position stays the same. so i was thinking i could click on the item based on their index, but don't know how to do it, say i want to click the last item, i hope you understand my issue. thanks

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Sure.  As mentioned, instead of the Caption, you can use a different property.  Whatever property you want and that can include the index.  It's just a matter of determining your array of properties and corresponding values of what you want.