How to get the count of links, images, buttons and edits in a web page using QTP

Write a Script to get the count of all the edits, images, buttons and links in a web page.

Before running the script in QTP the user needs to add the web page in the Object repository. Here we are using using differnet functions for each item to get the values.  


Function GetAllSpecificControls(Page, MicClass) Set Desc = Description.Create()
Desc("micclass").Value = MicClass
Set GetAllSpecificControls = Page.ChildObjects(Desc)
End Function

        Function GetAllEdits(Page)
        Set GetAllEdits = GetAllSpecificControls(Page, "WebEdit")
        End Function

             Function GetAllButtons(Page)
             Set GetAllButtons = GetAllSpecificControls(Page, "WebButton")
             End Function

Function GetAllLinks(Page)
Set GetAllLinks = GetAllSpecificControls(Page, "Link")
End Function

Function GetAllImages(Page)
Set GetAllImages = GetAllSpecificControls(Page, "Image")
End Function

Set oPage = Browser("Browser Name").Page("Page Name")
MsgBox "Number of Edits: " & GetAllEdits(oPage).Count
MsgBox "Number of Buttons: " & GetAllButtons(oPage).Count
MsgBox "Number of Links: " & GetAllLinks(oPage).Count
MsgBox "Number of Images: " & GetAllImages(oPage).Count

How to get the count of drop down values in QTP

Write a Script to get the count of the drop down items and then print the drop down values in an excel sheet from QTP.

Before running the script in QTP the user needs to add the dropdown box in the Object repository. Here we are using excel application object so that QTP creates and excel application. We are setting the excel application to be visible so that during run time we can see exactly whats happening. GetROProperty Item Count actaully counts the total number of items in the drop down during run time. Once this count is received we will pass them in a loop so that we can pass them to the excel sheet to be added one by one. msgbox is kept in the loop just to see that each item is being retreived. 


'Initializing an array with 3 columns and 4 rows

Dim Eobj Set Eobj= createobject ("Excel.Application")
Eobj.visible = true
Eobj.workbooks.add

Set obj = description.Create()
obj= Browser("Browser").Page("Page").Frame("Frame").WebList("city").GetROProperty("Items Count")
For i=1 to obj
obj2= Browser("Browser").Page("Page").Frame("Frame").WebList("city").GetItem(i)
Msgbox obj2
Eobj.cells(i,1).value = obj2
Next

Eobj.Activeworkbook.Saveas("c:\citylist.xls")

Eobj.quit

/* Tynt Insight tracker ----------------------------------------------- */