Professional Documents
Culture Documents
attributes of controls
Today I faced with the following task with QTP (QuickTest Professional) - how to
get some attributes (such as: font size, font color, background color and so on)
for any control on a web page?
Piece of cake! :)
Let's see ways how it can be done.
The task: get font size, font color, background color and others possible
parameters from the gmail.com start page:
The solution:
1. First of all, I tried to use GetROProperty method.
I selected "Welcome to Gmail" label with QTP object spy and added them
to Object Repository:
Help reading shown that it is possible to get needed properties for some
objects, for example, for Link. Please, see "Link Identification Properties"
from the QTP Help:
So, these properties work correctly for Link. For example, the following
code:
Browser("Welcome to Gmail").Page("Welcome to
Gmail").Link("About Gmail").GetROProperty("color")
returns value #0000ff for "About Gmail" link:
2. currentStyle object!
The main idea is to read:
WebElement("SomeName").Object.currentStyle.someProperty
For example, use:
o color property to get the color of the text
o backgroundColor property to get the backgroung color (behind
the content of the object)
o fontSize property to get the font size
o fontStyle property to get the font style
o fontFamily property to get the font family
o fontWeight property to get the font weight
o and so on
sColor = objWebEl.currentStyle.color
sBackgrColor = objWebEl.currentStyle.backgroundColor
sFontSize = objWebEl.currentStyle.fontSize
sFontStyle = objWebEl.currentStyle.fontStyle
sFontFamily = objWebEl.currentStyle.fontFamily
sFontWeight = objWebEl.currentStyle.fontWeight
Result is:
Summary: The simple way to get different attributes of controls from QTP is a
usage of currentStyle object .
Enjoy QuickTest Professional :)
Dmitry Motevich