There are several images on a web page. You need to:
- get the number of all images on the page
- process each image (for example, get its location)
Also, I'm going to explain QTP Descriptive Programming concepts.
Let's start with Google Book Search page:
I have recorded simple QTP script which:
- uses http://books.google.com as initial URL
- clicks 'Google Book Search' image:
Why have I recorded this script?
Because it will help us to investigate QTP Object Repository (OR) and properties of image.
Let's open Object Repository:
And then we check image's properties saved in Object Repository:
"html tag" property and its value "IMG", we can create general description for all images on the page. For that I use QTP Description object.
Description object is used to create a 'Properties' collection object. Each 'Property' object contains a property name and value pair.
The above code:
- creates Description object
- creates "html tag" property and sets its value to "IMG"
You can use the following code to get number of all images on a Web page:
Execute the above code and you will get a result like:
How does Description object work?Actually, QTP Description object is a part of QTP Descriptive Programming.
QTP Descriptive Programming (DP) is a way of working with objects without Object Repository (OR).
In our example, we couldn't know all images on a Web page in advance. So, we couldn't add them into QTP Object Repository. Instead of that, we created Description object with required property and its value.
Tips: We can use several properties assigned to Description object. For example:
When we pass Description object to ChildObjects QTP function, it returns the collection of child objects contained within the object (Page("Google Book Search")) and matched to Description object.
That's why we've got the list of all images on a page.
How to get additional properties of found images?
As you remember, we planned to process each image (get its location).
Let's open OR and check the additional recorded properties:
There are "src" property, which contains the URL address of the image file.
To get this property, we can use GetROProperty QTP function.
The final code is:
This code shows a location of each image from a Web page.
There is a message box with a location of first image:
Then the second image:
and so on for others images...
Tips: Use the table of the most popular properties of Image QTP control:
Tips: You can use the same approach to work with others UI controls - Links, WebEdit, WebList, etc.
- QTP Descriptive Programming - How to get number of objects
- QTP Descriptive Programming - How to perform operations on objects
- QTP Descriptive Programming - How to close browsers
- QTP - How to capture tool tip?
- QTP VIDEO - How to run QTP test from command line
- How to minimize/maximize QTP window before the QTP script execution
- All QTP visual tutorials
Do you have interesting thoughts/articles/notes on automated testing?
Please, feel free to send them. Join our team!