Wednesday, April 13, 2011

QTP-How to get number of controls (Links, Edits, Images, etc) with DP

Hi,

If you want to find the number of links, webedits, images etc controls on the page, then use following.

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("Google Sets").Page("Google Sets")

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

3 comments:

  1. thanx trupti your code was correct and good.
    can you share if want to make the code more dynamic IE not specifically for one web page

    ReplyDelete
  2. Replace

    Set oPage = Browser("Google Sets").Page("Google Sets")

    With

    Set oPage = Browser("title:=[browser title]").Page("title:=[page title]")

    ReplyDelete