Micro Focus QTP (UFT) Forums
How to select the first checkbox - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: How to select the first checkbox (/Thread-How-to-select-the-first-checkbox)



How to select the first checkbox - ramya511 - 05-22-2013

I need to perform a search criteria and it will bring list of deals, I need to select first checkbox and perform an action

This is the code I wrote

Code:
Set  Obj=Description.Create()
Obj("html tag").value="DIV"
Obj("outerhtml").value="<DIV class=x-grid3-check-col></DIV>"
obj("micclass").value="WebElement"
Set Obj= Browser("Revenue Editor").Page("Revenue Editor").Childobjects(Obj)
'Set Obj= Browser("Revenue Editor").Childobjects(Obj)
AllObj=Obj.count
msgbox AllObj

It gave correct number of checkbox, now I need to select the first checkbox, can you please tell me how to select the first checkbox?


I tried this code but it did not work

Code:
For i = 1 to 2
    Obj(i).set "ON"
Next



RE: How to select the first checkbox - basanth27 - 05-22-2013

Is your criteria only to select the first one? If yes then you dont have to iterate.
You could simply add the object to the repository and then SET it to ON. But if you want to highlight a 5th or 7th or loop through then you can use the below code. The below code will check all the checkboxes it has identified.
Code:
Set  Obj=Description.Create()
Obj("html tag").value="DIV"
Obj("outerhtml").value="<DIV class=x-grid3-check-col></DIV>"
obj("micclass").value="WebElement"
Set ObjChild= Browser("Revenue Editor").Page("Revenue Editor").Childobjects(Obj)
AllObj=ObjChild.count
msgbox AllObj
For i = 1 to AllObj
          ObjChild(i).set "ON"
Next

Does it help?


RE: How to select the first checkbox - venugqtp - 05-22-2013

Code:
Set Obj=Description.Create()
Obj("html tag").value="DIV"
Obj("outerhtml").value="<DIV class=x-grid3-check-col></DIV>"
obj("micclass").value="WebElement"
Set Obj = Browser("Revenue Editor").Page("Revenue Editor").Childobjects(Obj)
Obj(0).Click
you can't use Set method for "WebElement" object Type


RE: How to select the first checkbox - learnQtptips - 05-22-2013

If you need to check only the first checkbox, then you dont have to use the for..next loop as below
Code:
Set  Obj=Description.Create()
Obj("html tag").value="DIV"
Obj("outerhtml").value="<DIV class=x-grid3-check-col></DIV>"
obj("micclass").value="WebElement"
Set ObjChild= Browser("Revenue Editor").Page("Revenue Editor").Childobjects(Obj)
AllObj=ObjChild.count
ObjChild(0).Click 'first element is always a index 0
But if you have to compare the items with a particular deal then see below
Code:
Set  Obj=Description.Create()
Obj("html tag").value="DIV"
Obj("outerhtml").value="<DIV class=x-grid3-check-col></DIV>"
obj("micclass").value="WebElement"
Set ObjChild= Browser("Revenue Editor").Page("Revenue Editor").Childobjects(Obj)
AllObj=ObjChild.count
msgbox AllObj
For i = 0 to AllObj - 1
          if ObjChild(i).GetRoProperty(<property name>) = "<deal string>" then ObjChild(i).click
Next