Following are functions that may be useful when working on Web Tables.
' ******************************** Function Library *********************************
RegisterUserFunc "WebTable", "ObjectsByMicClass", "ObjectsByMicClass"
RegisterUserFunc "WebTable", "ItemByKeyColumn", "ItemByKeyColumn"
' Description: Returns a collection of objects. All the objects in a
' WebTable that have the specified MicClass
' Return Value: A collection of objects
' Obj - Test Object (WebTable)
' micClass - The micClass of the objects to retrieve
'---------------------------------------------------------------------------------------------------------
Function ObjectsByMicClass(Obj, micClass)
' Create a collection object to hold the items
Set objCollection = CreateObject("Scripting.Dictionary")
' Go over all the cells in the table, and look for objects with the specified micClass
ColumnCount=Table.ColumnCount(row)
For ItemIndex=0 to Table.ChildItemCount(row, col, micClass)-1
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
Set ObjectsbyMicClass = objCollection
' Description: Returns an item from a column, based on the value of a
' Obj - Test Object (WebTable)
' KeyColumnIndex - Index of the KeyColumn
' KeyColumnValue - Value to search for in the key column
' KeyItemIndex - Index of the value in the key column (if there is
' more than one). If 0, the first item will be used.
' TargetColumnIndex - Column from which to retrieve the target item
' micClass - The micClass of the target item
' TargetItemIndex - Index of the target item to retrieve (if there is
' more than one). If 0, the first item will be used.
' ----------------------------------------------------------------------------------------------------
Function ItemByKeyColumn(Obj, KeyColumnIndex, KeyColumnValue, KeyItemIndex, TargetColumnIndex, micClass, TargetItemIndex)
' If TargetItemIndex was not specified, use 1 as default
' If KeyColumnIndex was not specified, use 1 as default
' Look for KeyColumnValue in the key column to determine from which
' row to retrieve the target item
While Row <= RowCount And foundIndex < KeyItemIndex
CellData = Table.GetCellData(Row, KeyColumnIndex)
If CellData = KeyColumnValue Then
If foundIndex < KeyItemIndex Then
' Now that we know the row, retrieve the item (according to its micClass)
ChildItemsCount = Table.ChildItemCount(Row, TargetColumnIndex, micClass)
If ChildItemsCount > =1 And ChildItemsCount >= TargetItemIndex Then
Set GetItemByKeyColumn = Table.ChildItem(Row, TargetColumnIndex, micClass, TargetItemIndex-1)
' ******************* Examples that use these functions ******************************
' Using the ItemByKeyColumn function
Set obj = Browser("Table with objects").Page("Itenerary: Mercury Tours").WebTable("
msgbox obj.GetROProperty("innerhtml")
' Using the ObjectsByMicClass function
Set collection = Browser("Browser").Page("Page").WebTable("Table").ObjectsByMicClass("WebCheckBox")
If collection(i).GetROProperty("checked") Then
3 comments:
Thanks this was very useful for me.
Bhagawati
http://bhagawati-bugs.blogspot.com
Thanks, Really helpfull for all concept of webtable in mine project..great Work
Thanks Really great work on Web Table..
Post a Comment