QTP/UFT beginner tutorial – Getting the value of an object that requires you to hover over it -QTP/UFT

Happy Friday people!!! Today, we're going to celebrate the start of the weekend with an awesome lesson in QTP/UFT automation. I will cover how to get the value of a web object, that requires you to hover over it with a mouse. If you look below, I created a tool tip with a hover over pop up text. Hover over it with your mouse, and you should see the text "You did it". This will be the text that we're going to extract.

Before starting:

  1. Close all browsers except the browser in which you have this window open
  2. Close all other pages except this page

Now let's begin...

Hover over me to open tooltip

1. First, let's hover over the button to display the tool tip. Using our object spy tool, we can see that this object is a web element. I am using the unique innertext value with the  FireEvent("onmouseover") method to hover over the webelement.

Browser("Index:=0").Page("title:=.*").WebElement("innertext:=Hover over me to open tooltip ").FireEvent("onmouseover")

2. Initially, I get an error which states that the WebElement could not be recognized because there are more than one object with the same property. No problem! In this case, use an index to differentiate between the similar objects.

Browser("Index:=0").Page("title:=.*").WebElement("innertext:=Hover over me to open tooltip ", "Index:=1").FireEvent("onmouseover")

3. QTP/UFT is now running the code without any issues, but I don't see the hover over text like I'd like. In this case, we want to see if QTP/UFT is finding the right object. We can use the code below to highlight the object we are identifying.

Browser("Index:=0").Page("title:=.*").WebElement("innertext:=Hover over me to open tooltip ", "Index:=1").highlight

4. Now if we run it, we can see that the object is correctly being found by the tool. The issue is that it is not hovering over the object. I covered this issue in this tutorial Issues with clicking on objects

Take a look if you have a chance, but for now, I will just show you the fix.

Setting.WebPackage("ReplayType") = 2

Browser("Index:=2").Page("title:=.*").WebElement("innertext:=Hover over me to open tooltip ", "Index:=1").FireEvent("onmouseover")

Setting.WebPackage("ReplayType") = 1

By setting the replay type to 2 before hovering over the object, we are changing how UFT/QTP operates. It will now act as a user with direct mouse and keyboard movements. Run the code and you can see that we now hover over the webelement without a problem. The last part of the code resets the replay type to the default 1 value.

 

4. Now, let's figure out the property values for the "You did it" text. Click on the object spy tool, hold the Ctrl key over the object, and once the tool tip appears, let go of the Ctrl key and click on the "You did it" text. You should see that it's a web element. Now let's retrieve this value!

strSuccess = Browser("Index:=0").Page("title:=.*").WebElement("innertext:=You did it").GetROProperty("innertext")

MsgBox strSuccess 

I set the value I am returning to the variable strSuccess. Then I am printing that value using MsgBox to see if my code is working properly. Congratulations. That's all there is to it.

 Setting.WebPackage("ReplayType") = 2

Browser("Index:=0").Page("title:=.*").WebElement("innertext:=Hover over me to open tooltip ", "Index:=1").FireEvent("onmouseover")

Setting.WebPackage("ReplayType") = 1

Dima = Browser("Index:=0").Page("title:=.*").WebElement("innertext:=You did it").GetROProperty("innertext")

MsgBox Dima

The point of this tutorial is to give you an idea of how to interact with a variety of different scenarios and web elements. If you want to make your code a bit more robust and dynamic, check out my tutorial on identifying the browser and page dynamically. Post all of your questions and comments below!

Identifying Browser and Page Dynamically

 

Pin It on Pinterest

Clef two-factor authentication