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("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "Male"
Where "Male" 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("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender", "index:= 1").Select "Female"
This code is intended to select a radio button among two, what if you have a list of radio buttons let’s say 5-6 or more, than the above code won’t help. For that you need to create description of a radiogroup i.e. we will instruct everything to QTP.
''''''=====Initialize variables
Dim oWebRadio
Dim oWebRadioCount
Dim RadioToSelect_Val
''''''Create description using Description.Create build-in method
Set oWebRadio = Description.Create
oWebRadio ("micclass").value = "WebRadioGroup"
oWebRadio ("type").value = "radio"
oWebRadio ("name").value="Gender"
''''''Pass the description in another variable using ChildObjects method
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").ChildObjects(oWebRadio)
''''''Loop to select desired value
For i = 0 to oWebRadioCount
RadioToSelect = oWebRadioCount (i).GetROProperty("value")
oWebRadioCount (i).Select RadioToSelect
Next
''''''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.
'============= Ways to select value from WebList =======================
Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr").Select "#3"
Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr").Select "2218866589&15-5-2013"
Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "#0"
Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "Female"
'========== To Count Number and Name of WebRadioGrouppresent on a Page Using MicClass ======
'Example: 1 This page has One Radio Group
SystemUtil.Run "iexplore", "http://youngistaancafe.blogspot.com/2013/07/qtp-web-table_5925.html"
Set oWebRadio = Description.Create
oWebRadio("micclass").value="WebRadioGroup"
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").ChildObjects(oWebRadio)
vrCount = oWebRadioCount.Count
msgbox vrCount
For i=0 to vrCount-1
msgbox oWebRadioCount(i).GetROProperty("name")
Next
'Example: 2 This page has Two Radio Groups
SystemUtil.Run "iexplore", "http://youngistaancafe.blogspot.com/2013/07/student-registration-formhtml.html"
Set oWebRadio = Description.Create
oWebRadio("micclass").value="WebRadioGroup"
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").ChildObjects(oWebRadio)
vrCount = oWebRadioCount.Count
msgbox vrCount
For i=0 to vrCount-1
msgbox oWebRadioCount(i).GetROProperty("name")
Next
'To find Number of Radio Buttons present in particular Group along with its value
With Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr")
vrAllItem = .GetROProperty("all items")
msgbox vrAllItem
vrArr = Split(vrAllItem, ";", -1, 1)
For i=0 to UBound(vrArr)
msgbox vrArr(i)
vrLeftPNR = Left(vrArr(i),10)
msgbox vrLeftPNR
If vrPNR = vrLeftPNR Then
vrIndex = i
.Select "#"&vrIndex
Exit For
End If
Next
End With
'=========Select WebRadio button where PNR# is 5018866589================
vrPNR = "5018866589"
With Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr")
vrAllItem = .GetROProperty("all items")
msgbox vrAllItem
vrArr = Split(vrAllItem, ";", -1, 1)
For i=0 to UBound(vrArr)
msgbox vrArr(i)
vrLeftPNR = Left(vrArr(i),10)
msgbox vrLeftPNR
If vrPNR = vrLeftPNR Then
vrIndex = i
.Select "#"&vrIndex
Exit For
End If
Next
If you have two radio buttons on the screen for example Gender selection options the code below might give problem.
Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "Male"
Where "Male" 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("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender", "index:= 1").Select "Female"
This code is intended to select a radio button among two, what if you have a list of radio buttons let’s say 5-6 or more, than the above code won’t help. For that you need to create description of a radiogroup i.e. we will instruct everything to QTP.
''''''=====Initialize variables
Dim oWebRadio
Dim oWebRadioCount
Dim RadioToSelect_Val
''''''Create description using Description.Create build-in method
Set oWebRadio = Description.Create
oWebRadio ("micclass").value = "WebRadioGroup"
oWebRadio ("type").value = "radio"
oWebRadio ("name").value="Gender"
''''''Pass the description in another variable using ChildObjects method
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").ChildObjects(oWebRadio)
''''''Loop to select desired value
For i = 0 to oWebRadioCount
RadioToSelect = oWebRadioCount (i).GetROProperty("value")
oWebRadioCount (i).Select RadioToSelect
Next
''''''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.
'============= Ways to select value from WebList =======================
Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr").Select "#3"
Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr").Select "2218866589&15-5-2013"
Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "#0"
Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "Female"
'========== To Count Number and Name of WebRadioGrouppresent on a Page Using MicClass ======
'Example: 1 This page has One Radio Group
SystemUtil.Run "iexplore", "http://youngistaancafe.blogspot.com/2013/07/qtp-web-table_5925.html"
Set oWebRadio = Description.Create
oWebRadio("micclass").value="WebRadioGroup"
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").ChildObjects(oWebRadio)
vrCount = oWebRadioCount.Count
msgbox vrCount
For i=0 to vrCount-1
msgbox oWebRadioCount(i).GetROProperty("name")
Next
'Example: 2 This page has Two Radio Groups
SystemUtil.Run "iexplore", "http://youngistaancafe.blogspot.com/2013/07/student-registration-formhtml.html"
Set oWebRadio = Description.Create
oWebRadio("micclass").value="WebRadioGroup"
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").ChildObjects(oWebRadio)
vrCount = oWebRadioCount.Count
msgbox vrCount
For i=0 to vrCount-1
msgbox oWebRadioCount(i).GetROProperty("name")
Next
'To find Number of Radio Buttons present in particular Group along with its value
With Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr")
vrAllItem = .GetROProperty("all items")
msgbox vrAllItem
vrArr = Split(vrAllItem, ";", -1, 1)
For i=0 to UBound(vrArr)
msgbox vrArr(i)
vrLeftPNR = Left(vrArr(i),10)
msgbox vrLeftPNR
If vrPNR = vrLeftPNR Then
vrIndex = i
.Select "#"&vrIndex
Exit For
End If
Next
End With
'=========Select WebRadio button where PNR# is 5018866589================
vrPNR = "5018866589"
With Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr")
vrAllItem = .GetROProperty("all items")
msgbox vrAllItem
vrArr = Split(vrAllItem, ";", -1, 1)
For i=0 to UBound(vrArr)
msgbox vrArr(i)
vrLeftPNR = Left(vrArr(i),10)
msgbox vrLeftPNR
If vrPNR = vrLeftPNR Then
vrIndex = i
.Select "#"&vrIndex
Exit For
End If
Next
End With