Monday, January 19, 2009

How to retrieve tooltip in QTP

Downalod the Windows Application

Couple of days ago I was visiting the SQA forum and there someone have posted the question to retrieve the tooltip of the web button. And so I find out the couple of different way to retrieve the tooptip for web objects.

Retrieve the tooltip of the Web objects:

There isn't any direct property of any of the web object that gives you the tooltip. But if you will see the source code of the object you will find out that it is the title property of th object which appears as the tooltip.

Below are the couple of ways to retrieve the tooltip.


1)Retrive the tooltip from outerhtml property

The title property resides in the OuterHtml property of any object. So what i did is, i made a function to fetch the title property as below.
Example:
This retrives the tooltip of the Edit box appears on the "Google.com" website. The same way you can retrieve the tooltip of web buttons.




SystemUtil.Run "iexplore.exe","Google.com"
outerhtml = Browser("Title:=Google").page("title:=google").webedit("name:=q").GetROProperty("outerhtml")
msgbox Find_ToolTip( outerhtml )

Function Find_ToolTip(outerhtml)
temp = RegExp("title=.*""",outerhtml)
Find_ToolTip = RegExp(""".*""",temp)
End Function


Function RegExp(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search.
If Matches.count > 0 Then
RegExp = Matches(0).Value
else
REgExp=""
End If

End Function


Yeah yeah yeah... I know this is the tedious way to retrieve the tooltip. So Then something else comes in my mind and I found out the eaistest way to retreive it.

2) Retrieve tooltip using DOM.

You can easily retrieve the title property of the object using DOM.

Example:
msgbox Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").Object.title


Retrieve the tooltip of the Windows objects:

Retrieve tooltip of the windows object is easy too if you know it's class name. But you will not be able to retrieve the class name through the Object Spy that comes with the QTP.

The tooltip is windows of type tooltips_class32.

Example:
You need to download the gToolTip_Demo.zip and extract the exe file gTooltip.exe to run this example



Dialog("text:=Tool Tip Demo").WinButton("text:=OK").MouseMove 0,0
msgbox Window("nativeclass:=tooltips_class32").GetROProperty("text")

Dialog("text:=Tool Tip Demo").WinButton("text:=Cancel").MouseMove 0,0
msgbox Window("nativeclass:=tooltips_class32").GetROProperty("text")

Dialog("text:=Tool Tip Demo").WinEdit("attached text:=Password").MouseMove 0,0
msgbox Window("nativeclass:=tooltips_class32").GetROProperty("text")

Dialog("text:=Tool Tip Demo").WinEdit("attached text:=User ID","micClass:=WinEdit").MouseMove 0,0
msgbox Window("nativeclass:=tooltips_class32").GetROProperty("text")