Relevant Codes

A Test Development Resource for HP QuickTest Professional.

QTP: Get Link’s Mouse Over (Hover) Color

by Anshoo Arora on November 5, 2009

This post describes a simple technique that can enable retrieval of a Link’s onMouseOver color. The only trick is to change the ReplayType setting to Mouse Events while firing an onMouseOver event on the link. Changing the event cause an actual FireEvent action, that you would encounter when you hover the mouse on the link manually.

Below, you will see that the hover event is triggered with the ReplayType set to Mouse Events:

Setting.WebPackage("ReplayType") = 2
Browser("Browser").Link("Link").FireEvent "onMouseOver"
MsgBox Browser("Browser").Link("Link").Object.currentStyle.color
Setting.WebPackage("ReplayType") = 1

The above snippet can be simplified and be reused using the function below:

Function GetHoverColor(oLink)
        Setting.WebPackage("ReplayType") = 2
        oLink.FireEvent "onMouseOver"
        GetHoverColor = oLink.Object.currentStyle.color
        Setting.WebPackage("ReplayType") = 1
End Function
 
RegisterUserFunc "Link", "GetHoverColor", "GetHoverColor"

Now, whenever the link color is to be retrieved, you can simply call the “GetHoverColor” function as you would normally use the Click event:

MsgBox Browser("Browser").Page("Page").Link("Link").GetHoverColor

I hope you find this useful.

{ 15 comments… read them below or add one }

1 Rajiv Kumar Nandvani November 9, 2009 at 2:16 am

Hi Anshoo,

Today i go through from Your blog in goggle search.
realy you are doing great job.
keep it up

Reply

2 Anshoo Arora November 9, 2009 at 4:29 pm

Thank you, Rajiv. I hope you like reading the articles here :)

Reply

3 Selvam V November 11, 2009 at 2:40 am

Simple neat and very nice….

Reply

4 Anshoo Arora November 11, 2009 at 4:46 pm

Glad you liked it, Selvam :)

Reply

5 Rajesh January 28, 2010 at 2:05 pm

Its really nice. Can you please share few articles related to the below problem.

when I fire a mouseover event, I get a complete structure of a table. how to retrive the data from this. Can you Please share this info. thank u

Reply

6 Anshoo Arora January 29, 2010 at 1:47 pm

Hi Rajesh,

I’m not sure if I understand the scenario quite well. The table structure is retrieved when you onMouseOver it? What data are you trying to retrieve from the table? If possible, could you attach or e-mail me the HTML source of the document?

My email is anshoo.arora [at] relevantcodes.com

Reply

7 Anonymous February 18, 2010 at 11:57 pm

Thank you
Anshoo

The problem is now resolved. I learned the Table and is working good.

Reply

8 Anshoo Arora February 19, 2010 at 2:13 am

Great! :)

Reply

9 Raj February 18, 2010 at 6:08 pm

Great articles…. Keep it up

Reply

10 Anshoo Arora February 19, 2010 at 2:13 am

Thanks Raj :)

Reply

11 naveen March 11, 2010 at 12:19 am

Hi, Please Let me know how to read functions from DLLs we currently have .vbs files and we want to make them as DLLs and use the functions .Can u please let me know how to convert the.VBS files into dlls where we can hide the code from others with out loosing the flexibility to use the functions.

Reply

12 Anshoo Arora March 11, 2010 at 3:59 pm

Hi Naveen,

Please see this article. Any public method/property/variable can be accessed once you load the DLL through DOTNetFactory.

Reply

13 Mahalakshmi August 18, 2010 at 6:47 am

To select from the WebList box I am changing the Setting.WebPackage(“ReplayType”)=2 selecting the required item from the list and then on trying to reset the replay type to 1, QTP crash occurs..

Reply

14 Ralf August 30, 2010 at 5:44 am

Hi Anshoo,
how to do this with FF 3.5?

QTP 10.0 sends an Runtime-Error:
Line (83): “GetHoverColor = Link.Object.currentStyle.color”.

I have installed Patch QTPWEB_00046 – Add Support For Firefox 3.5
by the way, is their an Way to use FF 3.6?

best regarts
Ralf

Reply

15 Anshoo Arora September 2, 2010 at 7:42 am

Ralf,

Not sure if this will work in Firefox as it does not support the concept of .Object (yet). We’re primarily dealing with COM here, but the underlying technology of Firefox is different. I agree its very similar to COM, but its not exactly that – its XPCOM.

Reply

Leave a Comment

Previous post:

Next post: