Enumerating Application Objects

The code below illustrates one way of enumerating the application objects while performing an operation on each object. The following example can be found in the EnumerateApplication.vbs file located in the <Installdir>\CodeSamplesPlus folder.

Function EnumerateApp(ParentObj, Desc, OperationMethod, PostOperationMethod, RestoreMethod)
	dim ObjCol, CurrentObj, idx
	idx = 0
	' Retrieve a collection of all the objects of the given description
	Set ObjCol = ParentObj.ChildObjects(Desc)

	Do While (idx < ObjCol.Count)
		' Get the current object
		set CurrentObj = ObjCol.item(idx)

		' Perform the desired operation on the object
		eval("CurrentObj." & OperationMethod)

		' Perform the post operations (after the object operation)
		eval(PostOperationMethod & "(ParentObj, CurrentObj)")

		' Return the application to the original state
		eval(RestoreMethod & "(ParentObj, CurrentObj)")

		idx = idx + 1
		' Retrieve the collection of objects
		' (Since the application might have changed)
		Set ObjCol = ParentObj.ChildObjects(Desc)
	Loop
End Function

' ********************************** An Example of usage **********************
' Report all the pages referred to by the current page
' ***********************************************************************************

Function ReportPage(ParentObj, CurrentObj)
	dim FuncFilter, PageTitle

	PageTitle = ParentObj.GetROProperty("title")
	FuncFilter = Reporter.Filter
	Reporter.Filter = 0
	Reporter.ReportEvent 0, "Page Information", "page title " & PageTitle
	Reporter.Filter = FuncFilter
End Function

 BrowserBack(ParentObj, CurrentObj)
	BrowserObj.Back
End Function

' Save the Report Filter mode
OldFilter = Reporter.Filter
Reporter.Filter = 2 ' Enables Errors Only

' Create the description of the Link object
Set Desc = Description.Create()
Desc("html tag").Value = "A"

Set BrowserObj = Browser("creationtime:=0")
Set PageObj = BrowserObj.Page("index:=0")

' Start the enumeration
call EnumerateApp(PageObj, Desc, "Click", "ReportPage", "BrowserBack")

Reporter.Filter = OldFilter ' Returns the original filter