|
by jack
在QTP脚本编写的时候,我们可能会遇到这种检查点:比如获取checkbox的个数等等,这时会提出“获取页面上所有指定属性的对象”的需求。下面是用descrīption对象实现的一个函数,作用就是实现上述需求。
Function getItemList(PageObject,PropertyName,PropertyValue)
Dim oItemDesc
Dim n
Set ōItemDesc=descrīption.Create
If isarray(PropertyName) and isarray(PropertyValue) Then
Dim iCountPropertyName
Dim iCountPropertyValue
iCountPropertyName = ubound(PropertyName)
iCountPropertyValue = ubound(PropertyValue)
If iCountPropertyName <= iCountPropertyValue Then
For n=0 to ubound(PropertyName)
oItemDesc(PropertyName(n)).value=PropertyValue(n)
Next
Else
'lost property value
'msgbox "lost property value"
Exit Function
End If
Else If (not isarray(PropertyName)) and (not isarray(PropertyValue)) Then
oItemDesc(PropertyName).value=PropertyValue
Else
'error
'msgbox "error"
Exit Function
End If
End If
Set getItemList=PageObject.childobjects(oItemDesc)
End Function
输入参数有3个,page对象,属性名,属性值;其中属性名和属性值可以为数组,应用举例:
'取出页面所有编辑框
set ōChildList = getItemList(page("51Testing软件测试网"),"micclass","WebEdit")
'编辑框数量
iCountChildList = oChildList.count
'取出页面所有name含有“测试”的链接
set ōChildList = getItemList(page("51Testing软件测试网"),array("micclass","name"),array("Link","测试.*"))
'点击第二个链接
oChildList(1).click |
|