WORKING WITH QTP

TestEveryThinG

Get Text Location / ClickOnText QTP VB

Posted by rajivkumarnandvani on June 21, 2009

Hi All,

Now I am going to describle the undocumented feature of QTP that is ClickONText  method . Some time we require the object text location ( x ,y position ) in window so that we can click  that object by use  Get text location method. like this

rem  Open the “C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe” application.

SystemUtil.Run “C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe”,”C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe”,””

rem   Make the “Login” dialog box active.

Dialog(“Login”).Activate


rem  Click the “OK” button.

Dialog(“Login”).WinButton(“OK”).Click


rem Check whether the text “OK” is displayed in the “Flight Reservations” dialog box and store the location of the text in rem    arguments 2-5. Store the result in the variable ‘find’
.

find =Dialog(“Login”).Dialog(“Flight Reservations”).GetTextLocation (“OK” ,x1,y1,x2,y2)

rem Check whether (find = True) is true. If so:
If find =True  Then
Dialog(“Login”).Dialog(“Flight Reservations”).Click  (x1+x2)/2 ,(y1+y2)/2 rem Click the “Flight Reservations” ‘dialog box
else rem Otherwise:
msgbox  “not found OK text”
End If

Instead of Serached the text location in Window we can use directely method ClickonText like this it will automatically search the text and click the text area

Dialog(“Login”).Dialog(“Flight Reservations”).Clickontext “OK”

Advertisements

24 Responses to “Get Text Location / ClickOnText QTP VB”

  1. Subhash said

    Hi Rajiv,
    Great Effort, It will give a lot to others as well as you. You must continue.

  2. thanks buddy 🙂
    Its my pleasure..24/7 help desk

  3. vivin said

    superb!!!

  4. Thanks 😉

  5. Pasu said

    Hi all, I got a problem on GetTextLocation method. I’m trying to check with the text “Progress” on the existing screen and click on the text to review the document. I want the script to repeat the action until all the document is reviewed and the text “Progress” in not exist on the screen any more. However, it doesn’t work… It will fail to get the text in the 2nd iteration even the word “Progress” is still exist on the screen. Here are the code i have.

    Function WPDocumentList()
    Dim temp,SearchText
    temp=true
    Do WHILE temp = True
    SearchText = “Progress”
    temp=false
    temp = VbWindow(“VbWindow”).WinObject(“Afx:DocList”).GetTextLocation(SearchText,leftpos,toppos,rightpos,bottompos)
    If temp = True Then
    VbWindow(“VbWindow”).WinObject(“Afx:DocList”).Click leftpos,toppos
    VbWindow(“VbWindow”).VbButton(“Review Document”).Click
    wait(10)
    End If
    Loop
    End Function

  6. hi,
    It seems that after getting the text in first iteration u clicking ( VbWindow(“VbWindow”).WinObject(“Afx:DocList”).Click leftpos,toppos VbWindow(“VbWindow”).VbButton(“Review Document”).Click ) WinObject(“Afx:DocList”) getting change thats why in next iteration unable to get text
    Make sure that after click (VbWindow(“VbWindow”).WinObject(“Afx:DocList”) ) object must be there

    and Just check in debug mode what value u getting for temp in second iteration

  7. prasanna said

    need to open application from the notification area-(ie right side of the system tray.)using double click.

    The position of application in the notification area will not be same.

    ClickonText??? wher do u find.. i mean i dont see it and it doesnot accept when i type it?

  8. Hi,

    Are u talking abt web or windows application. It support in windows

  9. Tariq said

    Thanks with all my heart!

  10. Thanks you are most welcome.. 🙂

  11. Rajesh said

    Thanks Rajivkumar,

    Can you please tell me how you figured this method. As you mentioned it is an undocumented feature in qtp.

    Just curious, it would be great if you explain.

    Rajesh

  12. Hi Rajesh,
    in qtp when you press ctrl space after enter the . near to object it will give the hints which methods it will support there you will find this method too 🙂
    Dialog(“Login”).Dialog(“Flight Reservations”).
    after that press ctrl space
    Some other sites also mentioned this
    its just like luck by chance trail when i was seeing others method i find this one 🙂

  13. Raju said

    Hi

    when am using “ClickOntext” Method, am geting Run error “Object doesn’t support this property or method”

  14. Are you trying for web object or windows object.. If web then it will not work.

    Thanks

  15. Anonymous said

    ‘ Clickontext ‘ great job.
    thanks a lot …………..

  16. Thanks for reading the blog.. 🙂

  17. Raju said

    Actual hierarchy is swfwindow().window().Page().Frame().Winbutton().Click

    code
    swfwindow().window().ClickonText “Next >”

    When we use the above code “Clickontext” method on .Net Application, throwing “Compare Fail” error message.

    “Clickontext” method will work in .Net and WebApplications?

    Thanks in Advace.

  18. No it will not work for .Net and Web Applications . It seems this method is not supported for this. It works for windows based applications but not for all

    Thanks for reading the blog

  19. Anonymous said

    If window have text Ok in two or more positions then this “click on text “method will works?

  20. No it will give an error to identify the object use index property/or any other properties to make them differ from each other

  21. Anonymous said

    hi i am writing scripts using fire fox 13.0 .In a Dialog i have to Click on Upload button below was the code used

    result= Browser(“name:=.*”).Dialog(“regexpwndclass:=MozillaDialogClass”,”regexpwndtitle:=Mozilla Firefox”).GetTextLocation(“Upload”,l, t, r, b)

    Browser(“name:=.*”).Dialog(“regexpwndclass:=MozillaDialogClass”,”regexpwndtitle:=Mozilla Firefox”).Click l,t

    Note: Dialog has Word “upload” 5 times. Above code is clicking on first occurance of Word “Upload” which is in Url

    Kindly help how can i write scrpit so tat my Script will click on Upload button leaving all other 4 “upload” present in dialog

  22. ayushi said

    get textlocation fails for few of the text searched , do you have any workaround for the same?

  23. ayushi said

    i am trying the method ‘get text location’ for a .net application

  24. Sravani said

    Hi,

    please send the ans to my mail in urgent basis
    my question is have to login to webpage, know username but don’t know password then will go for forgot password when clicked on forgot password that displays one password like plain text(like uytre)have to retrieve that particular text and paste in the password edit-box, then the login page will be open?

    how can retrieve the text from that location and paste it into password edit-box????

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: