Using Runtime Attributes to Describe QTP Web Objects
Posted by admin - Jan 21, 2009 Articles, Barak Kinarty, QTips 0 2 Views : 1691 Receive Updates For This Category
Article Tools
- Print this page
- Add Comment
- Send to Friend
- Last Updated on :
Jul 17, 2011
Barak Kinarti has kindly contributed an extremely useful QTip on how to identify Web objects through their Runtime Attributes.
I assume that the reader is familiar with using Test-Object properties to describe QTP objects programmatically (you can refresh your memory on the technique here). Here below a typical example is shown:
Set ImgDesc = Description.Create
ImgDesc("html tag").Value ="IMG"
ImgDesc("file name").Value = "minimize\.gif"
ImgDesc("index").Value = 0
'And now we can use ImgDesc to locate the object within a webpage,
'and (for example) click it:
Browser("X").Page("Y").Image(ImgDesc).Click
This is all nice and good, but what if we do not want to (or cannot) use Test-Object properties, but rather “real” Runtime-Object properties?
In such a case we can exploit a feature provided by QTP, according to which, with a Description Object, it is possible to use the attribute/<runtime property> tag, instead of the usual Test Object tag, as given in the following example:
Set ImgDesc = Description.Create
ImgDesc("attribute/nodeName").Value ="IMG"
ImgDesc("attribute/nameProp").Value = "minimize\.gif"
ImgDesc("attribute/cs").Value = "Minimize"
So, when we want to describe a web-object using its Runtime properties, we need to precede the property name with the prefix: “attribute/”.
When is this useful? Well, sometimes the object’s Runtime properties are much more reliable than Test-Object properties (or perhaps are the only possible way to identify the object), so it is good to have the ability to use them in our scripts.
This is especially true in instances when the object has no unique properties at all, beside the special runtime property “UniqueID” (somewhat similar to the Handle property of window objects). This runtime property is so special, that it even does not show up on the object spy. However, it does exist, and you can use it as a last resort.
You can also use it in cases like this:
ImgProtocol=Browser("Application Performance").Page("Application Performance").Image("Precise").GetROProperty("attribute/protocol")
This will let you access an attribute of the runtime object and use it. Normally you would have to access the runtime object with .object before. Also,
Browser("index").Page("index").Link("All kind of").WaitProperty("attribute/readyState", "complete", 4000)
Is a very useful when you wish to wait for the page or for a certain object to load, the readystate attribute can be extremely useful..
We wish to thank Barak, for sharing with us this useful and effective QTip!


