Sunday, September 7, 2014

Insight Objects - GetVisibleText

Insight Objects - GetVisibleText

You will be able to use GetVisibleText method in QTP / UFT 12.01. It returns the text from the specified area.

Syntax of GetVisibleText
object.GetVisibleText ([Left], [Top], [Right], [Bottom])

If the Left, Top, Right, and Bottom arguments are not specified, the method returns all of the text within the visible part of the specified object.

The return value of GetVisibleText is string.

A small note from QTP /UFT 12.01 help:
The GetVisibleText method may behave differently in different run sessions depending on the operating system version you are using, service packs you have installed, other installed toolkits, the APIs used in your application, and so on. Therefore, when possible, it is highly recommended to use the GetROProperty Method or the Object property to retrieve the value of the text (or equivalent) property from an object in your application instead of using the GetVisibleText method.

A very simple example of GetVisibleText:

I recorded the below code using QTP /UFT 12.01 and Calculator.

From the above code, I copied the second line and pasted it as a last line. I also added the method GetVisibleText to this line. Msgbox is appended at the front of the line.

Finally run the code and see the result of GetVisibleText method in a message box.