Thursday, 28 April 2011

Highlight the text on page using the QTP

Hi All,
Someone asked me how to highlight the text on page using the QTP. So here I have created a function that will find the text on page and highlight it if finds else not.

REM  ——  Set page object     ———
set objpage = Browser("BrowserName").Page("Pagename")

call   HighLightTextPresentOnPage(objpage ,"News" )

Function HighLightTextPresentOnPage(byval objpage , byval Textvalue )

On error resume next

REM ——- Create child object description
Set childobj = Description.Create()
childobj("html tag").value=".*[A-Za-z0-9].*"
childobj("outertext").value =Textvalue

REM  ———-Create ALL child object 
set allobj = objpage.ChildObjects(childobj)

 REM here highlight method we will use that is in build in QTP for object
For i=1 to allobj.count-1
           If allobj.count > 0 then
              HighLightTextPresentOnPage = true
              HighLightTextPresentOnPage = false
           End if

             On Error GoTo 0
End Function

No comments:

Post a Comment

Which one is right ?