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
Advertisements

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

  1. Anonymous said

    Excellent. Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: