Hi. The function I am about to show you, counts the number of objects within an object. I'll show you what I mean...
Public Function fun_countObjectsWithinObjext(pstrObjectName, pstrObjInnertext, pintIndex)
Set objectDescription = Description.Create
objectDescription("micclass").value = pstrObjectName
Set counter = Browser("index:=0").Page("title:=.*").WebElement("innertext:="& pstrObjInnertext, "Index:="& pintIndex).ChildObjects(objectDescription)
1. Let's see how many web elements are within the yellow box web element above. Click on the object spy and highlight the whole yellow box.
2. Copy the innertext of this web element which should be "Access to anyone on our email listTest1"
3. Now call the function countObjectsWithinObjext. Since we are trying to find how many web elements are within the yellow web element box, your first parameter should be "WebElement"
4. Enter the inntertext from step two as our second parameter
fun_countObjectsWithinObjext "WebElement", "Access to anyone on our email listTest1"
5. Enter an index of 0 as the third parameter:
fun_countObjectsWithinObjext "WebElement", "Access to anyone on our email listTest1", 0
Now run the code and you should get a message with the value 2. There are two web elements withing the yellow web element box.
1. Access to anyone on our email list(WebElement)
Cool right? Post a comment below and let me know if this was helpful!
Latest posts by Admin (see all)
- SQA QTP tutorial – WebList identified as a web element and how to select an item from this list - December 9, 2015
- Automation QTP tutorial-double clicking on any object - December 4, 2015
- Software Automation QTP tutorial – 5 top reasons for using automation - November 23, 2015