Reputation: 1771
I'm just wondering if it's possible to uniquely identify a given object in an application through Quick Test Pro.
For example, if there are 10 Ok buttons on a web page, with no HTML or Javascript giving them unique identifiers, how would I choose the 3rd button?
Thanks for your help.
Upvotes: 1
Views: 469
Reputation: 21
First, you can modify my code below to print out all the text, or the names, etc.... This will show all items that match that are on the screen, even if the GUI Spy wont show them.
This might solve your issue by showing you a unique name that the spy couldn't pick up, then you can just use that to interact with the object, but, if that doesn't work, it will allow you to count the names to find the number of the one you want
for example
if it showed....
Edit
Edit
Edit
And you wanted the 3rd edit button on the screen, you would now know it was the 3rd item in this collection of children we just looked through, so, get your unique property this way, or get the number of the child you want by counting names, or text, etc... (just use the GetROProperty that will help you count the objects to get to the one you want)
Here's that code, look after the code for the rest of the solution...
'#####################################################################################
'# getObjects()
'# Desc: Change the oPageObject and run this function to return all the text from all
'# visible objects on the screen. This is helpful for getting info on objects
'# that the GUI Spy wont get values for.
'#####################################################################################
Function getObjects()
print "# getObjects"
Set oPageObject = Browser("yourValueHere").Page("yourValueHere").SlvWindow("YourValue")
Set oDesc = Description.Create()
oDesc("slvtypename").Value = "button" ' Set this to the describing feature
Set oChild = oPageObject.ChildObjects(oDesc)
' Counting number of child objects
MyObjCount = oChild.Count
Print MyObjCount
' Looping through child objects, select value in list when criteria is met
For TotalCount = 0 To MyObjCount-1
vName = oChild(TotalCount).GetRoProperty("name")
print vName' output name of objects
Next
End Function
Once you know the number, then change the code like this... In this case, we counted the names and found out we wanted the 2nd occurrence, and now will write code to click it.
Set oPageObject = Browser("yourValueHere").Page("yourValueHere").SlvWindow("YourValue")
Set oDesc = Description.Create()
oDesc("slvtypename").Value = "button" ' Set this to the describing feature
oChild(2).Click ' see, here we say, click the 2nd child.
This is a last ditch effort in my opinion It may break easier as if more of these are added or some removed, the number will no longer match, but... If its all you have left, go for it.
This is somewhat complex to explain as a simple answer, please feel free to email me for more information as there are many, many other things you can try before resorting to this that may work well.
The problem with using an index like the user above pointed out is that it wont work on all object types as there may not always be an index for a given object type.
Upvotes: 1
Reputation: 11
If you want to click on 3rd button then you need to use settoproperty function of QTP.
'In the Object repository you have to add index property as optional identifiers and set it to '0 for the first button. The you can use
Browser("").Page("").Frame("").WebButton("OK").Settoproperty "index", 2
Browser("").Page("").Frame("").WebButton("OK").Click
'It clicks on the 3rd button.
Upvotes: 1