QTP基础代码收集《三》

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 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)
  Table = Obj
  rowCount = Table.RowCount
 
  ' if TargetItemIndex was not specified, use 1 as deafult
  If TargetItemIndex < 1 Then
  TargetItemIndex = 1
  End If
  ' if KeyColumnIndex was not specified, use 1 as default
  If KeyItemIndex < 1 Then
  KeyItemIndex = 1
  End If
 
  ' look for KeyColumnValue in the key column to determine which
  ' row to retrieve the targe item from
  Row = 0
  foundIndex = 0
  While Row <= RowCount And foundIndex < KeyItemIndex
  Row = Row + 1
  CellData = Table.GetCellData(Row, KeyColumnIndex)
  If CellData = KeyColumnValue Then
  foundIndex = foundIndex + 1
  End If
  Wend
  If foundIndex < KeyItemIndex Then
  Exit Function
  End If
 
  ' Now that we know the row, retrieve the item (according to its micClass)
  ' from the target column.
  ChildItemsCount = Table.ChildItemCount(Row, TargetColumnIndex, micClass)
  If ChildItemsCount > =1 And ChildItemsCount >= TargetItemIndex Then
  Set GetItemByKeyColumn = Table.ChildItem(Row, TargetColumnIndex, micClass, TargetItemIndex-1)
  End If
  End Function
 
 
  ' ************************************ Examples that use these functions *******************************************************
 
 
  ' Using the ItemByKeyColumn Function
  Set &#333;bj = Browser("Table with objects").Page("Itenerary: Mercury Tours").WebTable("Acapulco to Zurich").ItemByKeyColumn(1,"FLIGHT",2,3,"WebElement",1)
  msgbox obj.GetROProperty("innerhtml")
 
  ' Using the ObjectsByMicClass function
  Set collection = Browser("Browser").Page("Page").WebTable("Table").ObjectsByMicClass("WebCheckBox")
  For i=1 to collection.count
  If collection(i).GetROProperty("checked") Then
  collection(i).Set "OFF"
  Else
  collection(i).Set "ON"
  End If
  Next
<script type="text/javascript" id="wumiiRelatedItems"> </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值