QTP Descriptive Programs Headline Animator

QTP Descriptive Programs

Wednesday, June 18, 2008

How to Find Count of Links, Link names and their URLs on a web Page?

Prerequisites: Not Required

Procedure: Paste the Below Code in QTP window and Click on Run

Code:
Set ObjDes = Description.Create() 'Creates a new Empty Description Object
ObjDes("html tag").Value = "A" 'Adding Properties and Values to Descript Object
Set IE = CreateObject ("InternetExplorer.Application") 'Creates an Object to Variable
IE.Visible = True 'Makes Internet Explorer as Visible
IE.Navigate "www.google.com" ''Opens google.com in Internet Explorer

Set ChildObjCount = Browser("Name:= Google.*").Page("Title:= Google.*").ChildObjects (ObjDes) 'Gets the count of all Child Objects based on added description
NumCounts = ChildObjCount.Count() ' Gets the count of Descript values
Reporter.ReportEvent micPass, "The Number of Links on this page is", "Links Count = "&NumCounts ' Prints the Count of Links of the Page in Test Results
For i = 0 to NumCounts - 1 ' Making a For Loop to get all Similar Descript Values
Htag = ChildObjCount(i).GetROProperty("innertext") ' Gets the inner text of the value
Href =ChildObjCount(i).GetROProperty("href") 'Gets the Href of the inner text
Reporter.ReportEvent micPass, "The Name of the Link with URL", "Name: "& Htag&" and Url:" & Href ' reports the Tag and Href values to Test Results
Next

Verification: Once the Script is executed and after test result window opened check the results are similar to below image


1 comment:

Anonymous said...

Interested article! Good work.
QTP descriptive programming is a powerful method.
Also, I used the same approach when worked with all images on a page:
QTP descriptive programming - images