Login   /   Register

Get a WebElement’s style

Rate this article
     2 votes, average: 4 out of 52 votes, average: 4 out of 52 votes, average: 4 out of 52 votes, average: 4 out of 52 votes, average: 4 out of 5
Loading ... Loading ...
April 11th, 2008 by Yaron Assa

While some of a WebElement’s style properties are available via it’s Test-Object properties (e.g. its height, visibility etc.), a lot of its visual styling is left unknown to QTP. This can be overcome via its Runtime .CurrentStyle property.

For example, this WebElement is the welcome header of AdvancedQTP’s main page:

'Grabe the WebElement
Set oWebElement = Browser("AdvancedQTP - the resource")._
                        Page("AdvancedQTP - the resource")._
                                WebElement("Welcome to AdvancedQTP")
 
'Grabe the WebElement’s Runtime-Object’s CurrentStyle object
Set oStyle = oWebElement.Object.CurrentStyle

 

As you can see by the debug screenshot, the CurrentStyle object holds many many useful propertis:

image

 

So for example, we can find out the object’s direction (ltr = left-to-right), font-family (Ariel), color (HTML code=#06c), indentation (0pt), borders, and other useful properties.

'This will print the WebElement’s text-color HTML code.
Msgbox oStyle.Color

Posted in Web

5 Responses to “Get a WebElement’s style”

  1. kinjalshah Says:

    [+]

    hi i have tried this example, but i am not able to get the objects after setting oWebElement.. does anyone explain me in d... ...

  2. mangazey Says:

    [+]

    I have created the similar QTP tutorial on QTP - get font size/color, background color and other attributes. It seems, getting of ... ...

  3. Vivekanand Says:

    [+]

    wonderfull solution that helped me to found these properties. But Object property is supported by IE only not by Mozilla firefox, ... ...

  4. Vithul Says:

    [-]

    Can anybody tell how to get the font size for the Swflabel in QTP using Vbscript

    Thanks in advance,
    Selvi

  5. spanish_biker79 Says:

    [+]

    How do you get all that information in the Debug screen? I'm using the standard QTP debug window and the only thing I can see is o... ...

Leave a Reply

You must be logged in to post a comment.

This article was viewed 1232 times