QTP基础代码收集《三》
来源:互联网 发布:数量关系知乎 编辑:程序博客网 时间:2024/05/22 06:22
5、WebTable功能函数集合:
' ************************************************** Function Library ********************************
' Registering both functions
RegisterUserFunc "WebTable", "ObjectsByMicClass", "ObjectsByMicClass"
RegisterUserFunc "WebTable", "ItemByKeyColumn", "ItemByKeyColumn"
' Function: ObjectsByMicClass
' Descrīption: Returns a collection of objects all the objects in a
' WebTable that have the specified MicClass
' Return Value: A Collection of Objects
' Arguments:
' Obj - Test Object (WebTable)
' micClass - The micClass of the objects to retrieve
'-----------------------------------------------------------------------------------------------------------
Function ObjectsByMicClass(Obj, micClass)
Set Table = Obj
' Create a collection object to hold the items
Set ōbjCollection = CreateObject("scrīpting.Dictionary")
' Go over all the cells in the table, and look for objects with the specified micClass
For row=1 to Table.RowCount
ColumnCount=Table.ColumnCount(row)
For col=1 to ColumnCount
For ItemIndex=0 to Table.ChildItemCount(row, col, micClass)-1
Set childItem=Nothing
Set childItem = Table.ChildItem(row, col, micClass, ItemIndex)
If Not childItem is Nothing Then
' If the cell contains a micClass object, add it to the collection
ItemKey = objCollection.Count + 1
objCollection.Add ItemKey, childItem
End if
Next
Next
Next
Set ōbjectsbyMicClass = objCollection
End Function
' Function: ItemByKeyColumn
' Descrīption: Returns an item from a column, based on the value of a
' key column
' Return Value: Object
' Arguments:
' Obj - Test Object (WebTable)
' KeyColumnIndex - Index