博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
QTP的那些事---webtable的一些重要使用集合精解
阅读量:5805 次
发布时间:2019-06-18

本文共 4501 字,大约阅读时间需要 15 分钟。

' ******************************** Function Library ********************************* ' Registering both functions RegisterUserFunc "WebTable", "ObjectsByMicClass", "ObjectsByMicClass" RegisterUserFunc "WebTable", "ItemByKeyColumn", "ItemByKeyColumn" ' 函数功能: ObjectsByMicClass ' 描述: Returns a collection of objects. All the objects in a ' WebTable that have the specified MicClass 得到webtable下面指定的一个micclass类型的元素的所有对象的集合' Return Value: A collection of objects    得到对象的集合' Arguments: 参数无' Obj - Test Object (WebTable) 测试对象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 objCollection = CreateObject("Scripting.Dictionary")    '字典集合,很重要的一个方式,存放的对象可以在action之间传递    ' Go over all the cells in the table, and look for objects with the specified micClass     For row=1 to Table.RowCount   '遍历webtable的所有行        ColumnCount=Table.ColumnCount(row)      '得到webtable中指定行的列数        For col=1 to ColumnCount      '遍及指定行的所有的列            For ItemIndex=0 to Table.ChildItemCount(row, col, micClass)-1   '遍及webtable中指定行,指定列的指定类型对象的个数                Set childItem=Nothing                 Set childItem = Table.ChildItem(row, col, micClass, ItemIndex)     '获得webtable中指定行,指定列中指定对象类型,加上特定的index的对象                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 ObjectsbyMicClass = objCollection   '返回获取到的对象的集合End Function '******************************************************' Function: ItemByKeyColumn ' Description: 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)     Set Table = Obj     rowCount = Table.RowCount    '获得webtable中总计的行数    ' If TargetItemIndex 没有指定,就采用默认的1    If TargetItemIndex < 1 Then         TargetItemIndex = 1     End If     ' 如果 KeyColumnIndex没有指定,采用默认的1    If KeyItemIndex < 1 Then         KeyItemIndex = 1     End If     ' Look for KeyColumnValue in the key column to determine from which     ' row to retrieve the target item     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 ' *******************函数使用例子 ****************************** ' 使用 ItemByKeyColumn 函数 例子Set obj = Browser("Table with objects").Page("Itenerary: Mercury Tours").WebTable("Acapulco to Zurich").ItemByKeyColumn(1,"FLIGHT",2,3,"WebElement",1) msgbox obj.GetROProperty("innerhtml") ' 使用 ObjectsByMicClass 函数例子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

转载于:https://www.cnblogs.com/alterhu/archive/2011/12/31/2309231.html

你可能感兴趣的文章
四、配置开机自动启动Nginx + PHP【LNMP安装 】
查看>>
LNMP一键安装
查看>>
SQL Server数据库概述
查看>>
Linux 目录结构及内容详解
查看>>
startx命令--Linux命令应用大词典729个命令解读
查看>>
华为3026c交换机配置tftp备份命令
查看>>
Oracle命令导入dmp文件
查看>>
OCP读书笔记(24) - 题库(ExamD)
查看>>
Http、TCP/IP协议与Socket之间的区别(转载)
查看>>
解决Unable to load R3 module ...VBoxDD.dll (VBoxDD):GetLastError=1790
查看>>
.net excel利用NPOI导入oracle
查看>>
vrpie在Visio Studio 中无法调试的问题
查看>>
第六课:数据库的基本工具
查看>>
关于二叉树重构的思索
查看>>
$_SERVER['SCRIPT_FLENAME']与__FILE__
查看>>
skynet实践(8)-接入websocket
查看>>
系统版本判断
查看>>
关于Css选择器优先级
查看>>
My97DatePicker 日历插件
查看>>
0603 学术诚信与职业道德
查看>>