Ask a Question

Click on a specific radio button in a table

SOLVED
salley
Frequent Contributor

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

10 REPLIES 10
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.

 

 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
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
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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
salley
Frequent Contributor

thanks, i don't have any static propery except the object type. idStr,objectIdentifier changes. the only solution i see is click on radio button based their index's , i just don't know how to pass the index number. Thanks

tristaanogre
Esteemed Contributor

The index number should be a property as well.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
salley
Frequent Contributor

Thank You , i'm using Source Index, now i see that this is also dynamic,,,,, 

tristaanogre
Esteemed Contributor

Can you provide a screenshot of the available properties in Object Spy for your radio button?


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
salley
Frequent Contributor

Sure, attaching one of the radio button's extended prperties, value changes based on user's input. Index changes as well, everything is dynamic except the objecttype is Radiobutton. 

AlexKaras
Champion Level 2

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.

 

I haven't seen the overall page markup for the given table, but it is quite a common thing for dynamic pages that do not have unique and stable identifiers for web elements, to apply multi-steps approach to get and use required web element.

As a possible example for your case:

-- Assuming, that for the given table you are not looking for just the radio button, but looking for the radio button that is in the right-most column of some row, and another column of this row contains identifying information (e.g. order number),

-- You may search for this identifying information first;

-- Then, using the knowledge of how the page is designed, you should figure-out / calculate the row;

-- Then, for the found row you should find its right-most column and search for the radio button that is within the found cell. (Note, this well might be not a real cell with <TD> markup, but something, that looks like the cell but has different markup. <DIV>, for example.)

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
cancel
Showing results for 
Search instead for 
Did you mean: