Working with WebRadioGroup

QTP WebRadioGroup means a radio button on the web page. Identifying and working with them can be easy or difficult. Sometimes they works out fine and at times executing the same code gives you error.

If you have two radio buttons on the screen for example Gender selection options the code below might give problem.

Browser("").Page("").WebRadioGroup("").Select "M"

Where "M" can be the id or the value of the radio button (Spy the object). So what is the problem in the code above? As there are two radio buttons QTP identifies them as same, so we need to differentiate between them. Index is a property by which you can differentiate, it tells the position of the object. So if we write the same code below with an additional index property it will work fine.

Browser("").Page("").WebRadioGroup("html id:=" ,"index:= 1").Select "M".

This code is intended to select a radio button among two, what if you have a list of radio buttons lets say 5-6 or more, than the above code wont help. For that you need to create description of a radiogroup i.e. we will instruct everything to QTP.

''''''Initialize variables
Dim oDescRadio
Dim oChildren_Tier
Dim RadioToSelect_Val

''''''Create description using Description.Create build-in method
Set oDescRadio = Description.Create
oDescRadio("micclass").value = "WebRadioGroup"
oDescRadio("type").value = "radio"
oDescRadio("name").value="the name"

''''''Pass the description in another variable using ChildObjects method
Set oChildren_Tier = Browser("").Page("").ChildObjects (oDescRadio)

''''''Loop to select desired value
For i = 0 to oChildren_Tier.Count - 1
RadioToSelect_Val = oChildren_Tier(i).GetROProperty("value")
oChildren_Tier(i).Select RadioToSelect_Val
Next

''''''Pass desired value like we passed #1 below
Browser("").Page("").WebRadioGroup("html tag:=INPUT","type:=radio","index:=1").Select "#1"

You can also use a datatable to select and pass the value dynamically. Just add DataTable("parameter name",Sheet) in place of "#1"

If you want to get number of radio buttons then use Count method. Create description using the same way we did above.

''''''Pass Child count in a variable
allItems = oChild.Count

''''''Loop & Use items count property to get Total items
For j = 0 to allItems-1
   itemsCount =oChild.Item(j).GetRoProperty("items count")
 
      If (itemsCount = 5) Then
          Print "Found 5 radio "
      else
          Print "More than 5 radio listed"
      End If

Next

So there are two ways to deal with descriptive programming, either pass the properties directly or create your descriptions and pass or select your values.

Comments

Popular posts from this blog

LoadRunner Controller

All about Dates using QTP