Monday, February 11, 2008

Background Color in QTP

You can use any of the below options to get the background color:


Write the below code (either 1 or 2) in the expert view of a new test and run it.


Var=Browser("Title:=Google").Page("Title:=Google").webelement("html tag:=body", "height:=521").object.currentstyle.backgroundcolor

msgbox Var




msgbox Var

The first code works only with WebElement objects.

WebElement object is a general web object that may represent any web object. It is never recorded, although we can use Description Programming with WebElement object to perform methods on any web objects in the website.

For example:


If you write the below line in the expert view of a new test and Run it, it will click the "I'm Feeling Lucky" button on the google page.

Browser("Google").Page("Google_2").WebButton("I'm Feeling Lucky").Click

This same above line can be written using webelement object as:

Browser("Google").Page("Google_2").Webelement("name:=I'm Feeling Lucky").Click

I think for getting the background color it all depends on the kind of objects you are working with because different applications have different objects which in turn have different properties (read both run-time and test).

E.g. below you can see that when I tried to get the properties for a Label with the help of an Object Spy, it does not show any property related to color or BackColor in the Test Object Properties radio button, but surely shows a BackColor property in Run-time Object Properties radio button. So make sure to check for both run-time and test properties before going to the conclusion that you cannot get the BackColor of an object.

I got success with this line:

a=SwfWindow(“Teller”).SwfLabel(“window id:=98234”).Object.backcolor

Msgbox a

So the world does not end at object.currentstyle.backgroundcolor or object.bgcolor or Object.backcolor, just explore it.