QTP - How to capture tool tip of link?

QTP - How to capture tool tip of link?

My friend asked me - How to capture a tool tip text in QTP?

For example, how to get tool tip ('Go to My Yahoo!') from the yahoo page:
Tooltip on Yahoo page
This QTP tutorial shows and explains How to get tool tip in QuickTest Professional.

Actually, this is not a difficult task. The steps are:
  1. Place mouse cursor over the link
  2. Wait for tool tip
  3. Get text of shown tool tip

This QTP script captures a text of a tool tip:
' Place mouse cursor over the link
Browser("Yahoo!").Page("Yahoo!").WebElement("text:=My Yahoo!").FireEvent "onmouseover"
wait 1
' Grab tooltip
ToolTip = Window("nativeclass:=tooltips_class32").GetROProperty("text")

Please, pay attention on details:
  1. We use FireEvent("onmouseover") to simulate mouse placing over the link
  2. Function wait(1) waits 1 second for a tool tip
  3. To get tool tip text, we use:
    Window("nativeclass:=tooltips_class32").GetROProperty("text")

Let's run our code and compare captured tool tip with expected ('Go to My Yahoo!'):
As you can see, above QTP script captures correct text of a Tool tip.
I hope, you will add this script to your QTP functions library.


Related articles:


Dear readers,
Do you have comments or questions on this topic? If yes, please post them.

It's very important to know your opinions...
They allow to create more useful, interesting, and informative blog. This is my primary goal.


--
Dmitry

9 comments:

Shaik's said...

This script is not working for me, it shows the following error
message :
Cannot identify the object "[ Window ]" (of class Window). Verify that this object's properties match an object currently displayed in your application.
and in details tab:
Line (7): "ToolTip = Window("nativeclass:=tooltips_class32").GetROProperty("text")"

Dmitry Motevich said...

@Shaik's,
It seems that tool tip is not shown.
Do you wait for its appearance?
Are you sure that it did disappear?

Anonymous said...

Hello,
i am testing a web application,
and it has alternate text when you mouse over a link.
the example you have provided is for tool tip.
can you answer how to capture the alternatetext?
and what exactly the line
("nativeclass:=tooltips_class32").GetROProperty("text")" does?
thanks

Dmitry Motevich said...

@kishore,
What is "alterante text"?
As I understand, this is a tool tip.

Did you try the solution shown in the present article? Did it work?

Anonymous said...

yes i tried the same code but didn't work.
can you explain the native class code?
i got the below error
Cannot identify the object "[ Window ]" (of class Window).
after using the getRO property, should i use if statement to get the text?

Anonymous said...

alternate text is, when you mouse over on any link, the text that is displayed underneath the link.
tool tip might also be the same, not sure but the tool tip code didn't work for the alternate text

Anonymous said...

hello, the script worked for me, but everytime mouseover comes, i have to manually move the mouse on to the link...is there any way that we can automate mouse over thing on to the link?

Anonymous said...

Hello Dmitry,
i have a question regarding mousehovering on links and how to test whether the link is underlined when mouse hovered on that link?
please reply

Unknown said...

Hi I have tried that.But Iam getting error that not able to identify the window class!