Thursday, March 20, 2008

QTP - Getting INPUT objects

I wrote a qtp (Quicktest Professional) code for listing INPUT element's objects. Descriptive Programming is a feature in QTP. It is used to handle dynamic objects. I will write later about Descriptive Programming. Here below function returns particular type of objects in a web page.

Function:



'Calling function to list editboxes
Set ObjEditAll = ListAllWebObjects (Browser("My APP").Page("First Form"),"text")

Function ListAllWebObjects (ObjContainer,sControlType)
' Getting all type of INPUT objects
Dim MyDescription,objEditBoxes,NoOfChildObjs,Counter,strReport
Dim sTemp, objEdit

'Initialization
'ListAllWebObjects = Nothing
Set MyDescription = Description.Create()
MyDescription("html tag").Value = "INPUT"
MyDescription("type").Value = sControlType

Set objEditBoxes = ObjContainer.ChildObjects(MyDescription)
NoOfChildObjs = objEditBoxes.Count

strReport = ObjContainer.ToString() & " contains the following child object(s):"
For Counter=0 to NoOfChildObjs-1
strReport = strReport & vbNewLine & objEditBoxes.Item(i).ToString()
set objEdit = objEditBoxes(Counter)

sTemp = objEdit.GetROProperty ("name")
Reporter.ReportEvent micDone, objEdit.ToString() & " - name property", sTemp

sTemp = objEdit.GetROProperty ("class")
'sTemp = objEdit.object.ClassName
Reporter.ReportEvent micDone, objEdit.ToString() & " - class property", sTemp

sTemp = objEdit.GetROProperty ("index")
Reporter.ReportEvent micDone, objEdit.ToString() & " - index property", sTemp

sTemp = objEdit.GetROProperty ("location")
Reporter.ReportEvent micDone, objEdit.ToString() & " - location property", sTemp

sTemp = objEdit.GetROProperty ("html id")
Reporter.ReportEvent micDone, objEdit.ToString() & " - html id property", sTemp

sTemp = objEdit.GetROProperty ("innerhtml")
Reporter.ReportEvent micDone, objEdit.ToString() & " - innerhtml property", sTemp

sTemp = objEdit.GetROProperty ("outerhtml")
Reporter.ReportEvent micDone, objEdit.ToString() & " - outerhtml property", sTemp

sTemp = objEdit.GetROProperty ("innertext")
Reporter.ReportEvent micDone, objEdit.ToString() & " - innertext property", sTemp

sTemp = objEdit.GetROProperty ("outertext")
Reporter.ReportEvent micDone, objEdit.ToString() & " - outertext property", sTemp

Next

set ListAllWebObjects = objEditBoxes

Reporter.ReportEvent micDone, ObjContainer.ToString() & " child objects", strReport
End Function

1 comment:

Ravinder Singroha said...

Hi
Ho can i handle Popup by Descriptive Programming in QTP

Thnaks & Regards
Ravinder Singroha