Saturday 29 August 2015

Click on String using getTextLocation method - QTP

set objRef= Browser("MSN.com").Page("MSN.com")
objRef.highlight
ClickString="ENTERTAINMENT"
Call ClickonString(objRef, ClickString)
Function ClickonString(objRef, ClickString)
   ClickonString= False
    If IsObject(objRef) Then
'        objRef.Highlight
        wait 1
        intHwnd=objRef.getROProperty("hwnd")  '' get the window handler of the browser page..
        intL = -1
        intT =  -1
        intR =  -1
        intB =  -1
        On error resume next
        blnCaptureText= TextUtil.getTextLocation(ClickString, intHwnd, intL, intT, intR, intB)
        If blnCaptureText=True Then
             x = (intL + intR)/2
             y = (intT + intB)/2
             wait 1
             Window("hwnd:="& intHwnd).highlight
            
             Window("hwnd:="& intHwnd).Click x , y
            ClickonString= True
        End If
    End if
End Function


Working eg..

No comments:

Post a Comment