Micro Focus QTP (UFT) Forums
Help Regarding GetTextLocation - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Help Regarding GetTextLocation (/Thread-Help-Regarding-GetTextLocation)



Help Regarding GetTextLocation - koti.deva - 12-08-2009

Hi all, how do we get to know the co ordinates of a Search text from QTP, which occurs more than once.

or how do we know the No.of occurances of a text on a page???

i was trying with below code.

Code:
Call GetTextLocation

Sub GetTextLocation()
l = -1
t =  -1
r =  -1
b=  -1
InputLink="http://www.sportingbet.com"
Set GameRef=Window("regexpwndtitle:=Microsoft Internet Explorer","text:="&InputLink&".*").WinObject("Object class:=MacromediaFlashPlayerActiveX")
If GameRef.Exist Then
    result =GameRef.GetTextLocation("Spin", l, t, r, b)
    If result Then
    MsgBox "Text found. Coordinates:" & l & "," & t & "," & r & "," & b
        x = (l+r) / 2
        y = (t+b) / 2
        GameRef.Click x,y,0
        End If
End If
End Sub


when i run this script this will identify the first occurance of "Spin", but how to get the Nth occurance of Random Button.

In my case "Spin" is found two times as
1.Last Spin as Plain text and
2.Spin - A button

i need to click on Spin Button , where as it is clicking on Last Spin Plain Text.


RE: Help Regarding GetTextLocation - sreekanth chilam - 12-08-2009

Hi ,

Try with "TextUtil" Utility object.
There is method called "GetTextLocation" associated with this Object.

Syntax:
TextUtil.GetTextLocation(TextToFind, hWnd, Left, Top, Right, Bottom[, MatchWholeWordOnly])
Return Value: Boolean

Example:
The below code searches for the word "Mercury" within the entire screen.
Code:
l = -1
t = -1
r = -1
b = -1
Succeeded=TextUtil.GetTextLocation("16",0,l,t,r,b)
msgbox Succeeded

Once its found , you could go for DeviceReplay,WSH so on so forth for clicking on that.


RE: Help Regarding GetTextLocation - venkatbatchu - 12-09-2009

Hi Sreekanth,
Thanks for letting us about the below information,

I have a small problem regarding this,

U have mentioned "Text to find" is "16" and the type of this property is string

But u were telling that
The following example searches for the word Mercury within the entire screen and clicks it if the word is found

Could you please refresh me with the above one,

Thanks,
Venkat.Batchu


RE: Help Regarding GetTextLocation - koti.deva - 12-09-2009

Hi Srikanth , Thanks for the Reply.

Can you please elobarate how to use that for my scenario. I Have Last Spin and Spin in my page. How to use that Textutil object for my scenario. and one more thing , in the above eexample , what that 16 mean ?


RE: Help Regarding GetTextLocation - sreekanth chilam - 12-09-2009

Hi Venkat/Koti,

Yep, it should be "mercury" instead of "16" in the example.
Fyi, As part of finding the text loc., I came to know about the "TextUtil" utility Object in QTP Help.

@venkat: Henceforth I suggested to check with the above object.
You refer the QTP help for "TextUtil" object for more info. & try to implement for your scenario.

Hope I am clear on this Smile


RE: Help Regarding GetTextLocation - venkatbatchu - 12-09-2009

Hey Sreekanth,
Its strange that even in Help also it is documented wrongly,
I posted about by seeing help thats the reason i have pasted the entire context as mentioned in the help like "The following example searches for the word Mercury within the entire screen and clicks it if the word is found" .
Any way thanks alot
Thanks,
Venkat.Batchu


RE: Help Regarding GetTextLocation - chaitali - 02-05-2014

The given code works fine for Mozilla 2.0 but not working for Mozilla Firefox v11.0.

I am unable to find text using the TextUtil function GetTextLocation().
Is there any equivalent function for testing on Mozilla 11.

Please reply ASAP with appropriate function or if any Addin is required.
You can also let me know if any other way is there to work with Tool bars on Mozilla v11.