QTP在webtable中查找指定字符
’ 首先獲取WebTable對象,然后通過ChildItem獲取指定單元格中的鏈接對象,并單擊該鏈接: ’ 獲取WebTable對象 Set objTable = Browser("請登錄 博都網").Page("我的文章").WebTable("文章標題") intRow = 2 intCol = 1 ’ 通過ChildItem獲取單元格中的鏈接對象 Set objLink = objTable.ChildItem(intRow, intCol, "Link" , 0) ’ 單擊鏈接 objLink.click _______________________________________________ ’獲取webtable的行數,并查找指定的內容 numRows = Browser("請登錄 博都網_2").Page("我的文章").WebTable("文章標題").RowCount For i=2 to numRows title_text =Browser("請登錄 博都網_2").Page("我的文章").WebTable("文章標題").GetCellData(i,1) If trim(title_text) = trim(articleTitle) Then reporter.ReportEvent 0,"測試成功","文章列表顯示新添加的文章標題" Exit For End If Next ’如果table有很多頁,數據不在第一頁,怎么查找? ’’’’’’’’’’’Function : 在webTable中查找元素’’’’’’’’’ Function FindedItemInTable(pageObj1,WebTable_Obj1,searchStr,PageNum) ’ Finded :標記是否從table里找到數據 ’ currentPage:當前頁;numRows:當前頁的行數 Dim Finded,currentPage Finded = false ’從第一頁開始查找。 For currentPage = 1 to PageNum ’==================初始化:保證從第一頁開始搜索========================== ’ If currentPage = 1 Then ’ pageObj.Link("pageLink").SetTOProperty "text",1 ’ pageObj.Link("pageLink").SetTOProperty "href","javascript:forward(1)" ’ If pageObj.Link("text:=1","href:=javascript:forward(1)").Exist(1) Then ’ pageObj.Link("text:=1").Click ’ End If ’ End If
’============================================ If currentPage >1 Then pageObj.Link("pageLink").SetTOProperty "text",currentPage pageObj.Link("pageLink").SetTOProperty "href","javascript:forward("¤tPage&")" pageObj.Link("text:="¤tPage).Click pageObj.Sync msgbox pageObj.GetROProperty("url") End If ’獲得當前頁的行數,開始逐行搜索 numRows = WebTable_Obj.GetROProperty("rows") msgbox numRows For i=2 to numRows ItemStr =Cstr(WebTable_Obj.GetCellData(i,1)) If trim(ItemStr) = trim(searchStr) Then reporter.ReportEvent 0,"搜索成功","元素位于第"¤tPage&"頁,第"&i&"行" Finded = true Exit For End If Next ’找到了,退出 If finded = true Then Exit For End If Next If finded = false Then msgbox "沒有找到數據!" End If
’============================================
If currentPage >1 Then
pageObj.Link("pageLink").SetTOProperty "text",currentPage
pageObj.Link("pageLink").SetTOProperty "href","javascript:forward("¤tPage&")"
pageObj.Link("text:="¤tPage).Click
pageObj.Sync
msgbox pageObj.GetROProperty("url")
End If
’獲得當前頁的行數,開始逐行搜索
numRows = WebTable_Obj.GetROProperty("rows")
msgbox numRows
For i=2 to numRows
ItemStr =Cstr(WebTable_Obj.GetCellData(i,1))
If trim(ItemStr) = trim(searchStr) Then
reporter.ReportEvent 0,"搜索成功","元素位于第"¤tPage&"頁,第"&i&"行"
Finded = true
Exit For
End If
Next
’找到了,退出
If finded = true Then
Exit For
End If
Next
If finded = false Then
msgbox "沒有找到數據!"
End If
posted on 2014-07-17 09:43 順其自然EVO 閱讀(479) 評論(0) 編輯 收藏 所屬分類: 測試學習專欄 、qtp