QTP - Capturing tool tips of images

QTP - Capturing tool tips of images

In my previous post (QTP - How to capture tool tip?) I shown an example on capturing tool tip of Web page link.
That solution uses FireEvent("onmouseover") and GetROProperty("text") to get tool tip of a link.


Now, I'm going to show how to show how to capture tool tips of images located on a Web page.

Actually, the solution is simple.
To capture a tool tip of an image, we can get value of "alt" Run-time Object property with GetROProperty("alt") function:
Browser("brw").Page("pg").GetROProperty("alt")

Let's verify this code in practice. For example, let's check tooltips from Wikipedia Main page:

I've prepared QTP script, which gets all image from this page and checks their tooltips ("alt" property):
Dim descImage, listImages, attrAltText, attrSrcText

Browser("Main Page - Wikipedia,").Sync
Browser("Main Page - Wikipedia,").Page("Main Page - Wikipedia,").Sync

' Create description for all images on a Web page.
' For that we use "html tag" property and its value "IMG"
Set descImage = Description.Create
descImage("html tag").value = "IMG"

' Get all images which match the above description
Set listImages = Browser("Main Page - Wikipedia,").Page("Main Page - Wikipedia,").ChildObjects(descImage)

' Check tool tips of images
For i = 0 To listImages.Count - 1
    attrAltText = listImages(i).GetROProperty("alt")
    attrSrcText = listImages(i).GetROProperty("src")

    If attrAltText <> "" Then
        MsgBox "Image src: " & attrSrcText & vbNewLine & "Tool tip: " & attrAltText
    End If
Next

When I run this code in QTP, it shows all images containing non-empty tool tip:
(click the image to enlarge it)

The same message boxes will be shown for others images on a Web page.

So, our solution is simple - use GetROProperty("alt") function to get tool tip of image.
As you can see - it works correctly.


Related articles:


Do you like this QTP visual tutorial? Would you like to receive them in the future?
If yes, please subscribe to this blog RSS feed or by Email. (How to subscribe? VIDEO guide)

--
Dmitry

4 comments:

Anonymous said...

Hi Dmitry,

i read ur blog and found very interesting. your blog solved many queries regarding QTP.
I am working on QTP from few month. currently i m working on "search" criteria of a web portal. i m not getting the right approach for "search". please provide me with some script to "verify searched Results". my id is: vikas_goel28@yahoo.com

Thanks a lot

Dmitry Motevich said...

2Anonymous:
Just try to imaging - How would you check the search engine if you test it manually?

I think, it depends on the requirements and specifications of your search engine...

Also, you can ask developers for recommendations on manual testing...
Try to search - for example how Google tests his search?

After that you will be able to start automated testing.

Anonymous said...

Can we check with QTP/vbscript whether an "img tag" got an alt attribute or not.

Because when we use Object.GetROProperty("alt") with an image which does not have an "alt attribute" or with an image which has alt=""

The result for both will be an empty string which is not the right way..

How to resolve this issue any idea???

Dmitry Motevich said...

Dear Readers!
Thank you very much for you comments!

Since this article was published more than one year ago, I've just disabled an adding of new comments for this article.