QuickTest Pro (9.0 or 8.2) method: WebRadioGroup.SelectByText
We've had to solve this problem quite a bit, so Will finally turned it into an object method.
Here's the problem:
Milk Butter CheeseYou want to be able to say "Select the 'Butter' radio button", but the enterprising and oh-so-efficient programmer has made it so that each option has a value that corresponds to some GUID (e.g. "AFED-0839-02E8A5-0923CDB"), and "Option A" is nowhere to be found anywhere in the object's properties.
The method below allows you to send the text you wish to select, and the radio group will know exactly which button to select.
Select a Radio Button based on the adjacent descriptive text
- The WebRadioGroup to use
- The text to look for
- optional: The sWhere statement for getAdjacentText. Default is afterEnd
- optional: The Index number of the matched button to select. 0 selects first match, 1 selects second. Default is 0
-
Public Function WebRadioGroupSelectByText ( ByRef oRadGroup, sSelectText, _
-
sWhereOpt, sIndexOpt )
-
If isNull(sWhereOpt) Then
-
sWhereOpt = "afterEnd"
-
End If
-
-
If isNull(sIndexOpt) Then
-
sIndexOpt = 0
-
End If
-
-
sMatches = Array()
-
-
Set oParent = oRadGroup.GetTOProperty("parent")
-
radName = oRadGroup.GetROProperty("name")
-
Set oRadioButtons = oParent.Object.GetElementsByName( radName )
-
-
For each oElement in oRadioButtons
-
sName = oElement.getAdjacentText("afterEnd")
-
If sSelectText = sName Then
-
ArrayPush sMatches, oElement.Value
-
End If
-
Next
-
-
If Ubound(sMatches) <0 Then
-
' TODO: report error...item doesn't exist in list.
-
Exit Function
-
End If
-
-
If Ubound(sMatches) <sIndexOpt Then
-
sIndexOpt = Ubound(sMatches)
-
' TODO: report warning...index doesn't exist. selecting last match
-
End If
-
-
sSelectValue = sMatches(sIndexOpt)
-
oRadGroup.Select sSelectValue
-
-
End Function
-
RegisterUserFunc "WebRadioGroup", "SelectByText", "WebRadioGroupSelectByText"
Now, to select the radio button I want, I just to this:
-
Browser("B").Page("P").WebRadioGroup("All Options").SelectByText "Option B"
Note that this performs an exact string match. The next step is to create our WebRadioGroup.SmartSelect function, which would be much more flexible, and would allow for partial matches of either adjascent text or the traditional button values. It would also allow for pattern matching via regular expressions. We'll post that one later.
Tags: Functions, QTP 9, QTP-8.2, QuickTest Pro, Software-Testing, VBScript


April 13th, 2006 at 1:53 am
First of all, your GUID is not really a GUID at all, no guid’s contain a ‘g’. It looks like your development staff is exposing ID’s in the form of SQL Server UUID’s to the presentation layer. This is perfectly acceptable especially when you stop to consider the I18N and L10N ramifications of doing what you requested to expose “Option A” back to the code behind.
Reply to Bob
June 15th, 2006 at 8:38 am
Hi
Iam Shahid,newbie to QTP.
My query is as follows
QTP is unable to recognize the radio button
i.e., every time a new “ID” is generated.
First of all iam “adding destination” and every time a time a new “Destination id” is generated.
While performing any operation(modify/delete) on the added destination,QTP unable to recognize the SYSTEM GENERATED ID.
Please send me reply ASAP,so that i can capture
“SYSTEM GENERATED ID”
THE code is as follows
Browser(”XXXXXX”).Page(”XXX”).WebRadioGroup(”XXXX”).Select “177″
The properties for the radio button as follows
name=myradio
html tag=INPUT
Reply to shahid
September 13th, 2006 at 4:09 am
u can go to standard properties and enable regular expression check box or use descriptive method
micclass(”property1:value1″,”property2:value2″)
first one is for manditory properties second for assessive properties
Reply to swappy
September 22nd, 2006 at 2:43 am
what main advantage&Disadvantage in QTP compare to other tools
let me know
Reply to Kishore