WORKING WITH QTP

TestEveryThinG

Highlight the text on page using the QTP

Posted by rajivkumarnandvani on May 25, 2011

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(“micclass”).value=”WebElement”
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
    allobj.Item(i).HighLight
Next
           If allobj.count > 0 then
              HighLightTextPresentOnPage = true
           Else
              HighLightTextPresentOnPage = false
           End if
             On Error GoTo 0
End Function

One Response to “Highlight the text on page using the QTP”

  1. Anonymous said

    Excellent. Thank you!

Leave a comment