奋斗在现在,输赢在将来
QTP遍历对象
上一篇 /
下一篇 2012-03-14 15:24:13
/ 个人分类:QTP
1.QTP在对页面中的对象进行遍历前首先要确定当前所要遍历对象的页面中的对象数量,而获取页面中的对象数量的方法有很多种:
NO.1---->object.count
Dim countNum
countNum=object.count '获取对象的数量
For countNum=0 to countNum-1
object(countNum).Click
Next
NO.2---->GetAllObjectsByClass '通过类名来获取指定对象的数量
NO.3---->GetElementByID
'使用IE COM启动IE
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True '设置可见
oIE.Navigate "http://www.baidu.com" '跳转URL
'等待IE页面加载完毕
While oIE.Busy: Wend
'获取Document对象
Set oDoc = oIE.Document
'使用DOM对测试对象进行操作
With oDoc
'搜索框输入
.getElementByID("kw").value = "test object"
'点击百度搜索
.getElementByID("sb").Click
End With
Set oDoc = Nothing
Ser IE = Nothing
No.4---->GetElementByName
'使用IE COM启动IE
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True '设置可见
oIE.Navigate "http://www.baidu.com" '跳转URL
'等待IE页面加载完毕
While oIE.Busy: Wend
'获取Document对象
Set oDoc = oIE.Document
'获取元素名为WD的集合
Set oEdits = oDoc.getElementsByName("wd")
'遍历对象并对其进行操作
For Each oEdit In oEdits
oEdit.value = "zzxxbb112"
Next
'点击百度搜索
oDoc.getElementByID("sb").Click
Set oDoc = Nothing
Ser IE = Nothing
收藏
举报
TAG: