由于在QTP中,对于下拉列表的对象默认是WebList,但是研发人员自己开发下拉列表后,对象发生变化,对象变成WebElement,以下就是针对开发自定义下拉列表取值方式:
1. 开发自定义下拉列表取值方法(一个页面中有多个下拉列表,且对象属性值一样,如何参数化且遍历取值?)
Set objPage = Browser("name:=XXX").Page("title:=XXX")
'检查回放模式 1、表示事件跟踪模式 2、表示鼠标跟踪模式
Setting.WebPackage("ReplayType") = 2
>>‘在没有参数化时,只针对页面中一个下拉列表取值
SelectDropDownBox objPage,"DropDownListName","DropDownListValue"
>>‘参数化多个下拉列表,针对当前页面中所有下拉列表取值
Fori = 1 to 2
SelectDropDownBox
objPage,DataTable("TitleName",dtGlobalSheet),DataTable("DropDownValue", dtGlobalSheet)
DataTable.GetSheet("Global").SetNextRow
Next
'主体代码-------------------------------------------------------------------------------
If ListNum.count =1 Then
ListNum(0).Click
End If
Public FunctiongetItemList(PageObject,PropertyName,PropertyValue)
Dim oDesc
Dim n
Set oDesc = Description.Create
If isarray(PropertyName) andisarray(PropertyValue) Then
DimiCountPropertyName,iCountPropertyValue
iCountPropertyName =ubound(PropertyName)
iCountPropertyValue =ubound(PropertyValue)
If iCountPropertyName <=iCountPropertyValue Then
For n = 0 Toubound(PropertyName)
oDesc(PropertyName(n)).value=PropertyValue(n)
Next
Else
Exit Function
End If
ElseIf (not isarray(PropertyName)) and(not isarray(PropertyValue)) Then
oDesc(PropertyName).value=PropertyValue
Else
Exit Function
End If
set getItemList =PageObject.childobjects(oDesc)
End Function