QTP三种对象识别方法:
1.ObjectRepository 对象库
利用SPY抓取对象,放入QTP对象库。
2.ProgrammaticDescription 描述编程对象
Arr = Array("One","Two","Three")
For i = LBound(Arr) to UBound(Arr)
Browser("title:=.*”).Page("title:=.*").WebButton("name:="&Arr(i)).Click
Next
3.DescriptionObject 描述对象
Set Desc = Description.Create()
Desc("html tag").Value = "button"
Desc("html tag").RegularExpression = False
'Arr = Array("One","Two","Three")
'For i = LBound(Arr) to UBound(Arr)
' Desc("name").Value = Arr(i)
' Browser("title:=.*”).Page("title:=.*").WebButton(Desc).Click
'Next
Set Buttons = Browser("title:=.*”).Page("title:=.*").ChildObjects(Desc)
For i = 0 to Buttons.Count-1
Buttons(i).Click
Next
例子:在百度上实验吧
A.ProgrammaticDescription
SystemUtil.Run "iexplore.exe","www.baidu.com"
Browser("name:=百度一下,你就知道").Page("title:=百度一下,你就知道").WebEdit("html id:=kw1").Set "testdao"
Browser("name:=百度一下,你就知道.*").Page("title:=百度一下,你就知道").WebButton("html id:=su1").Click
B.DescriptionObject
SystemUtil.Run "iexplore.exe","www.baidu.com"
oDesc("html id").Value = "kw1"
Browser("name:=百度一下,你就知道").Page("title:=百度一下,你就知道").WebEdit(oDesc).Set "testdao"