WebTable中查找包含指定文字的行

Function GetRowWithText(Obj, ByVal Text, StartFromRow, RegExpression)

bReg = LCase(RegExpression)

Set oDOM = Obj.Object

If bReg Then

Set oReg = new RegExp
oReg.Pattern = Text
oReg.Global = True
oReg.IgnoreCase = True
Else

Text = UCase(Trim(Text))

End if

Dim iColStart, iRowStart

If IsNull(StartFromRow) Then

iStartRow = 0

Else

iStartRow = StartFromRow - 1

End If

Dim i,j

For i = iStartRow to oDOM.rows.length - 1

Dim rowText
'Get the text of the row
rowText = Trim(UCase(oDOM.rows(i).innerText))
If Not bReg then
If Text = cellText Then
GetRowWithText = i + 1
oDOM.rows(i).scrollIntoView
Exit Function
End If
Else
'Check if the rowText matched the pattern
If (oReg.test(rowText)) Then
GetRowWithText = i + 1
oDOM.rows(i).scrollIntoView
Exit Function
End if
End if
Next

'Nothing found lets exit
GetRowWithText = -1

End Function

RegisterUserFunc "WebTable","GetRowWithText","GetRowWithText"

 

Msgbox Browser("Browser").Page("Page").WebTable("Book").GetRowWithText(".*QuickTest Professional Unplugged(.|\s)*2nd.*", 2, True)

posted @ 2013-06-21 11:22  dushuai  阅读(149)  评论(0编辑  收藏  举报