With UFT, it is very straightforward to access identification properties using GetROProperty
and CheckProperty
. However, this limits the scope of what can be checked, as TOs bring many properties that may be required. Fortunately, at least in web applications, we can also use native properties for object identification. In this recipe, we will demonstrate this feature using adapted examples from the previous recipes.
We will identify the input query WebEdit
object using a Description
object. In Action
, we will put the following code:
Set desc=Description.Create desc("attribute/nodeName").value="INPUT|input" desc("attribute/nodeName").RegularExpression = true desc("attribute/name").value="q" set oQuery=Browser("title:=Google").Page("title:=Google").WebEdit(desc) With oQuery If .exist(0) Then .highlight End If End With Set oQuery=nothing Set desc=nothing
Basically, this code works exactly as detailed in the Using the Description object recipe. The difference is in the way we defined the properties in the Description
object; while in the previous example we used identification properties, here we use native or runtime properties. The attribute
(or prefix) variable indicates that it is a runtime property. Recall that the standard windows Test Objects lack runtime properties and object capabilities. The name of the property must be valid.
The reader may ask, when would using native properties be useful? There are several cases in which it would be useful, as follows:
Description
object identifier might be the last resort and the only possibility to achieve unique object identification.Object
property. For example:ImgProtocol=Browser("App Perform").Page("Application Performance").Image("Precise").GetROProperty("attribute/protocol")
UniqueID
native attribute, which is not even available through the UFT Spy. This property is similar to hWnd we know from Windows applications, and it can be useful when the default properties of an object change during the automation run session, making identification through parameterized properties very demanding. We would then identify the target object once, get UniqueID
, and then use it across the runtime session. For example:'Get the UniqueID for an identified Web element ImgID=Browser("Browser").Page("Page").Image("Image").GetROProperty("attribute/UniqueID") 'Use the UniqueID with an inline description Browser("Browser").Page("Page").Image("attribute/UniqueID:=”&ImgID).Click
Refer to an article by Meir Bar-Tal at http://www.advancedqtp.com/using-runtimeattributes-to-describe-qtp-web-objects/.