QTP中如何快速獲取Page中的物件個數
relevantcodes.com的《QTP: Retrieve The Count of Objects in a Browser Efficiently》這篇文章介紹瞭如何封裝一個類來快速獲取到某個頁面中指定型別的物件的個數:
http://relevantcodes.com/qtp-quickly-retrieve-object-count/
封裝的類如下所示:
Class clsClassCount
Public CountType
'—————————————————————————————————————————————
' Name: Function GetClassCount (Public)
'
' Purpose:
'
' Input:
' BaseObject- Object containing the ClassName objects
' ClassName- MicClass for which the count is being retrieved for
'
' Output:
' Integer
'
' Author: Anshoo Arora
'
'—————————————————————————————————————————————
Public Function GetClassCount( BaseObject, ClassName ) ' As Integer
'—————————————————————————————————————————————
BaseObject.Init
If Not BaseObject.Exist( 0 ) Then
Reporter.ReportEvent micWarning, "GetClassCount", "BaseObject was not found."
GetClassCount = -1
Exit Function
End If
Dim oDesc, intCount
intCount = 0
Set oDesc = Description.Create
oDesc( "micclass" ).Value = ClassName
intCount = BaseObject.ChildObjects( oDesc ).Count
If Not CountType = "ALL" Then
oDesc( "x" ).Value = 0
intCount = intCount - BaseObject.ChildObjects( oDesc ).Count
End If
GetClassCount = intCount
End Function
End Class
Public refClassCount: Set refClassCount = New clsClassCount
'—————————————————————————————————————————————
' Name: Function GetObjectCount (Public)
'
' Purpose: Retrieve object count (visible + hidden)
'
' Input:
' BaseObject- Object containing the ClassName objects
' ClassName- MicClass for which the count is being retrieved for
'
' Output:
' Integer
'—————————————————————————————————————————————
Public Function GetObjectCount( BaseObject, ClassName ) ' As Integer
'—————————————————————————————————————————————
refClassCount.CountType = "ALL"
GetObjectCount = refClassCount.GetClassCount( BaseObject, ClassName )
End Function
'—————————————————————————————————————————————
' Name: Function GetVisibleObjectCount (Public)
'
' Purpose: Retrieve visible objects count
'
' Input:
' BaseObject- Object containing the ClassName objects
' ClassName- MicClass for which the count is being retrieved for
'
' Output:
' Integer
'—————————————————————————————————————————————
Public Function GetVisibleObjectCount( BaseObject, ClassName ) ' As Integer
'—————————————————————————————————————————————
refClassCount.CountType = ""
GetVisibleObjectCount = refClassCount.GetClassCount( BaseObject, ClassName )
End Function
支援獲取所有物件的個數以及可見物件的個數:
GetObjectCount: Retrieves the total count of objects on the webpage. This includes hidden + non-hidden objects.
GetVisibleObjectCount: This retrieves the number of non-hidden objects on the webpage.
使用的例子如下所示:
'This is where the objects are being searched for:
Set BaseObject = Browser("title:=.*實用性測試.*").Page("micclass:=Page")
Print BaseObject.Exist
' Retrieve the total number of Link Objects
MsgBox GetObjectCount( BaseObject, "Link" )
' Retrieve the total non-hidden number of Link Objects
MsgBox GetVisibleObjectCount( BaseObject, "Link" )
相關文章
- WPF中TreeView控制元件如何獲取選中的TreeViewItem物件?View控制元件物件
- js如何獲取指定元素在陣列中個數JS陣列
- SOLIDWORKS如何獲取模型中的引數Solid模型
- js如何獲取指定物件中含有屬性的個數JS物件
- 在Linux中,如何獲取CPU的總核心數?Linux
- 在RFT中如何通過指令碼獲取已新增到某個指令碼中的測試物件?指令碼物件
- XPAGES 中CGI變數的獲取變數
- Java中獲取Class物件的三種方式Java物件
- jQuery如何獲取iframe中的元素jQuery
- Nodejs獲取url路徑中的各個引數NodeJS
- javascript如何獲取指定元素在陣列中的數目JavaScript陣列
- 在ActionForm中如何獲取session中的資料?ORMSession
- 獲取request中的查詢引數
- js獲取url地址中的引數JS
- struts之Action中獲取request、response物件的方法物件
- C#中如何獲取二維陣列的行數和列數?C#陣列
- 如何在 Janus 中獲取 WebRTC 的流Web
- Oracle獲取資料庫中的物件建立語句Oracle資料庫物件
- 在SpringMVC中獲取request物件的幾種方式SpringMVC物件
- 03 #### `__dict__` , 用於獲取物件中的成員物件
- js獲取url連結中的引數JS
- 如何使用jQuery獲取物件的尺寸jQuery物件
- 在RFT中如何獲取JTable中的所有資料?
- js 取陣列中某個物件的集合JS陣列物件
- 獲取某個資料所在資料列表中的行數 mysqlMySql
- python 中如何判斷獲取檢視變數的型別Python變數型別
- SSIS中Sql任務中獲取系統變數的方式SQL變數
- python中獲取如何Series值Python
- Rust中如何獲取最大字串?Rust字串
- SQL Server中獲取一個資料庫的所有表的列數SQLServer資料庫
- js 獲取 table 中的每一個tdJS
- 如何獲取 Linux 中的目錄大小Linux
- MySQL 如何獲取執行中的Queries資訊?MySql
- 用python獲取mysql中的錶行數PythonMySql
- 獲取url中?後面傳遞的引數
- Vue入門指南-08 Vue中的標籤/如何獲取DOM元素(快速上手vue)Vue
- 反射獲取注入到spring中的類物件的工具類反射Spring物件
- SQL SERVER 儲存過程 獲取三個數中的最大值SQLServer儲存過程