Tuesday 27 August 2013

How to retrieve tooltip in QTP


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


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

No comments:

Post a Comment