GetTextLocation / GetVisibleText
If for some reason QTP/UFT is unable to recognize an object in an application then you may use GetTextLocation / GetVisibleText.
GetTextLocation
GetTextLocation verifies whether the stated text string is contained in the specified window area and returns true or false accordingly.
Syntax of GetTextLocation
object.GetTextLocation (TextToFind, Left, Top, Right, Bottom, [MatchWholeWordOnly])
-MatchWholeWordOnly is optional, rest all are required. A boolean True or False value is returned.
-You can set the Left, Top, Right, and Bottom coordinates to -1 to search for the text string within the object's entire window.
Example of GetTextLocation:
Open the login dialog as shown and run the code written in Descriptive Programming below:
Output:
In the above code y will contain True and user will be able to login into the application.
GetVisibleText
GetVisibleText returns the text from the stated area.
Syntax of GetVisibleText
object.GetVisibleText ([Left], [Top], [Right], [Bottom])
-The Left, Top, Right and Bottom coordinates are optional. An object is of type WinButton. A string value is returned.
Example of GetVisibleText:
Open the login dialog as shown and run the code written in Descriptive Programming below:
Output:
In the above code the message box will show text "Cancel".
GetVisibleText
HP itself recommends using GetROProperty method to retrieve the value of the text (or equivalent) property from an object in your application instead of using the GetVisibleText method as the results of GetVisibleText may be different in different run sessions depending on the operating system version you are using, service packs you have installed etc.
Below is another example where GetTextLocation is able to recognize even special characters:
If for some reason QTP/UFT is unable to recognize an object in an application then you may use GetTextLocation / GetVisibleText.
GetTextLocation
GetTextLocation verifies whether the stated text string is contained in the specified window area and returns true or false accordingly.
Syntax of GetTextLocation
object.GetTextLocation (TextToFind, Left, Top, Right, Bottom, [MatchWholeWordOnly])
-MatchWholeWordOnly is optional, rest all are required. A boolean True or False value is returned.
-You can set the Left, Top, Right, and Bottom coordinates to -1 to search for the text string within the object's entire window.
Example of GetTextLocation:
Open the login dialog as shown and run the code written in Descriptive Programming below:
l = -1 t = -1 r = -1 b = -1 y= Dialog("text:=Login").GetTextLocation ("OK", 0 ,l,t,r,b) msgbox y If y = "True" Then Dialog("text:=Login").Activate Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set "sachin" Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Type micTab Dialog("text:=Login").WinEdit("attached text:=Password:")._ SetSecure "51e02a499eb8ef07baf933c069405c7f8b5ca87d" Dialog("text:=Login").WinButton("text:=OK").Click Else msgbox ("Dummy") End If
Output:
In the above code y will contain True and user will be able to login into the application.
GetVisibleText
GetVisibleText returns the text from the stated area.
Syntax of GetVisibleText
object.GetVisibleText ([Left], [Top], [Right], [Bottom])
-The Left, Top, Right and Bottom coordinates are optional. An object is of type WinButton. A string value is returned.
Example of GetVisibleText:
Open the login dialog as shown and run the code written in Descriptive Programming below:
Dialog("text:=Login").Activate var=Dialog("text:=Login").WinButton("text:=Cancel").GetVisibleText msgbox (var)
Output:
In the above code the message box will show text "Cancel".
GetVisibleText
HP itself recommends using GetROProperty method to retrieve the value of the text (or equivalent) property from an object in your application instead of using the GetVisibleText method as the results of GetVisibleText may be different in different run sessions depending on the operating system version you are using, service packs you have installed etc.
Below is another example where GetTextLocation is able to recognize even special characters:
l = -1 t = -1 r = -1 b = -1 Window("Flight Reservation").Activate y=Window("Flight Reservation").WinEdit("Name:").GetTextLocation ("~", 0 ,l,t,r,b) msgbox y