Saturday, August 22, 2026

UFT Ordinal Identifiers: Object Identification Guide

Mastering Object Identification in UFT: A Comprehensive Guide to Ordinal Identifiers

In the world of automated testing with Unified Functional Testing (UFT), effectively identifying objects is crucial for creating reliable and maintainable test scripts. When standard identification methods fall short, ordinal identifiers serve as a powerful fallback mechanism to ensure your tests can accurately locate and interact with UI elements even in complex scenarios.

Mastering Object Identification in UFT: A Comprehensive Guide to Ordinal Identifiers


Understanding Object Identification in UFT

Unified Functional Testing (UFT) uses a sophisticated object identification system to recognize and interact with various UI elements during test execution. This process begins when you record a test, as UFT captures properties of each object you interact with, creating a unique description that allows it to locate the same object during subsequent runs. The primary identification methods rely on mandatory and assistive properties—mandatory properties are those that must match exactly, while assistive properties provide additional context to narrow down potential matches. However, in complex applications with multiple similar objects, these standard methods may not be sufficient. This is where ordinal identifiers come into play as a backup mechanism. Ordinal identifiers assign a numerical value to objects based on their position or order relative to other similar objects, ensuring UFT can distinguish between them when all other properties are identical. Understanding this hierarchy of identification methods is crucial for creating robust automated tests that can withstand minor UI changes while maintaining reliability.

What Are Ordinal Identifiers and When Are They Needed?

Ordinal identifiers are essentially fallback mechanisms that UFT employs when the standard object identification properties fail to uniquely identify an element. These identifiers assign a numerical value to objects based on their position or order within a container or window, allowing UFT to distinguish between similar elements when their descriptive properties are identical. You'll typically need ordinal identifiers in scenarios where multiple objects share the same set of properties, making them indistinguishable through conventional means. Common situations include:

  • Multiple buttons with identical text and properties in a dialog box
  • Repeated list items in a data grid or table
  • Dynamic elements that change their positions but maintain similar characteristics

When UFT encounters such scenarios during test execution, it automatically falls back to using ordinal identifiers to determine which specific object to interact with. While this ensures test reliability, over-reliance on ordinal identifiers can make tests brittle, as any change in the object's position may cause test failures. Therefore, understanding when and how to use these identifiers is essential for creating maintainable automated test suites that can adapt to application changes while remaining reliable.

Types of Ordinal Identifiers in UFT

UFT provides several types of ordinal identifiers, each serving a specific purpose in object identification. The most commonly used ordinal identifiers include location, index, and creation time. Location identifiers determine an object's position relative to its parent container, using coordinates like x and y positions. Index identifiers assign a sequential number to objects based on their order within a collection, with the first object typically having an index of 0. Creation time identifiers track when an object was created during runtime, helping distinguish between objects that appear identical but are instantiated at different times.

Each type of ordinal identifier serves different scenarios:

  • Location is useful when objects are positioned in a consistent grid-like layout
  • Index works well for lists, tables, or any collection of similar items
  • Creation time is valuable for dynamically generated elements that appear after the application loads
' Example of using location-based ordinal identifier
Set obj = Browser("Page").Page("HomePage").WebElement("location:=15;20")
obj.Click

' Example of using index-based ordinal identifier
Set obj = Browser("Page").Page("HomePage").WebList("index:=3")
obj.Select "Option 1"

' Example of using creation time-based ordinal identifier
Set obj = Browser("Page").Page("HomePage").Window("creationtime:=2")
obj.Maximize

Understanding these different types and their appropriate use cases allows testers to create more reliable and maintainable automated tests that can accurately identify objects even in complex scenarios.

Implementing Ordinal Identifiers in Your Test Scripts

Implementing ordinal identifiers in UFT test scripts can be done both manually and through the Object Identification settings. When manually adding ordinal identifiers to your code, you can specify them as additional properties in your object descriptions. For example, you might use the "index" property to identify the third item in a list when all items have identical properties. Alternatively, you can configure UFT to learn ordinal identifiers automatically by adjusting the settings in the Object Identification dialog box. This approach allows you to specify which ordinal identifier types UFT should consider when attempting to identify objects.

When working with ordinal identifiers in your test scripts, it's important to consider the following best practices:

  • Use ordinal identifiers sparingly, as they can make tests brittle
  • Combine ordinal identifiers with other properties when possible
  • Document your use of ordinal identifiers for future maintenance
  • Regularly review tests that rely heavily on ordinal identifiers
' Example of a test script using ordinal identifiers
SystemUtil.Run "iexplore.exe", "https://example.com"

' Using index to identify the third button
Browser("title:=.*Example.*").Page("title:=.*Example.*").WebButton("index:=2").Click

' Using location to identify a specific element
Browser("title:=.*Example.*").Page("title:=.*Example.*").WebElement("x:=120;y:=80").Click

' Using creation time to identify a dynamically opened window
Browser("title:=.*Example.*").Page("title:=.*Example.*").Link("text:=Open Window").Click
Browser("title:=.*Example.*").Window("creationtime:=1").Close

By implementing ordinal identifiers thoughtfully, you can significantly improve the reliability of your automated tests in complex scenarios where standard identification methods fall short.

Configuring UFT for Ordinal Identifier Usage

Before diving deeper into implementation, it's essential to understand how to configure UFT to work effectively with ordinal identifiers. The Object Identification settings in UFT allow you to control how the tool handles ordinal identifiers during test execution and object identification. To access these settings, navigate to Tools > Object Identification in the UFT menu. Here, you can specify which ordinal identifier types UFT should consider when attempting to identify objects.

Within the Object Identification dialog, you'll find tabs for different object types (Web, Windows, Java, etc.). For each object type, you can configure the ordinal identifier priority by adjusting the ordinal identifier values. Lower values indicate higher priority, meaning UFT will attempt to use that ordinal identifier type first when other properties fail to uniquely identify an object.

It's also worth noting that you can set the Smart Identification feature to work in conjunction with ordinal identifiers. Smart Identification uses a set of base filter properties and optional ordinal identifiers to identify objects when the main identification fails. By configuring these settings appropriately, you can create a robust object identification strategy that minimizes test failures while maximizing maintainability.

Advanced Techniques for Ordinal Identifiers

While basic usage of ordinal identifiers can solve many object identification challenges, advanced techniques can further enhance your testing capabilities. One such technique is the use of regular expressions with ordinal identifiers to handle dynamic or partially consistent object properties. For example, you might combine an index with a regular expression to identify objects based on patterns in their properties.

Another advanced approach is creating custom functions that encapsulate complex ordinal identifier logic. This can be particularly useful when dealing with nested objects or dynamic UI elements that change position frequently. By centralizing this logic in functions, you can improve code reusability and maintainability.

' Example of a custom function for handling dynamic ordinal identifiers
Function GetDynamicObject(browser, page, objectClass, ordinalType, ordinalValue, optionalProperty)
    On Error Resume Next
    Dim obj
    Dim description
    
    Set description = Description.Create()
    description("micclass").Value = objectClass
    
    ' Add optional property if provided
    If IsMissing(optionalProperty) = False Then
        For Each prop In optionalProperty
            description(prop.name).Value = prop.value
        Next
    End If
    
    ' Add ordinal identifier
    Select Case LCase(ordinalType)
        Case "index"
            description("index").Value = ordinalValue
        Case "location"
            description("location").Value = ordinalValue
        Case "creationtime"
            description("creationtime").Value = ordinalValue
    End Select
    
    Set obj = browser(page).ChildObjects(description)
    
    If obj.Count > 0 Then
        Set GetDynamicObject = obj(ordinalValue)
    Else
        Set GetDynamicObject = Nothing
    End If
End Function

' Usage example
Dim propArray(1)
Set propArray(0) = CreateObject("Scripting.Dictionary")
propArray(0).Add "text", "Submit"

Set myButton = GetDynamicObject(Browser("title:=.*Example.*"), _
                                Page("title:=.*Example.*"), _
                                "WebButton", _
                                "index", _
                                2, _
                                propArray)

If Not myButton Is Nothing Then
    myButton.Click
Else
    Reporter.ReportEvent micWarning, "Button not found", "Could not locate the specified button"
End If

Best Practices for Using Ordinal Identifiers

While ordinal identifiers can be powerful tools in your UFT testing arsenal, they should be used judiciously to maintain test reliability and maintainability. One key best practice is to prioritize other identification methods whenever possible, as ordinal identifiers are more susceptible to breaking with minor UI changes. When you must use ordinal identifiers, consider combining them with one or two other unique properties to create a more robust identification strategy. This hybrid approach reduces the likelihood of test failures while still maintaining the ability to identify objects in complex scenarios.

Another important consideration is documentation. When your tests rely on ordinal identifiers, be sure to document the rationale behind their use. This documentation should explain why standard properties were insufficient and how the ordinal identifier ensures reliable object identification. Such notes can be invaluable during future maintenance when application changes might necessitate test updates.

Regular maintenance is also crucial for tests using ordinal identifiers. Schedule periodic reviews of these tests, especially after application updates or UI changes. During these reviews, assess whether the ordinal identifiers are still appropriate or if alternative identification methods have become available. By staying proactive, you can prevent potential test failures and ensure your automated tests continue to provide reliable feedback.

Troubleshooting Common Ordinal Identifier Issues

Despite their utility, ordinal identifiers can sometimes introduce challenges in your automated tests. One common issue is test instability caused by objects changing their position or order. When this happens, tests that previously relied on a specific index or location may fail to locate the correct object. To address this, regularly review and update your tests after application changes, and consider whether alternative identification methods might be more appropriate.

Another frequent problem is the overuse of ordinal identifiers, which can mask underlying issues with test object identification. If you find yourself frequently using ordinal identifiers across your test suite, it may indicate that your object repository needs refinement or that your application's UI structure requires optimization. In such cases, consider revisiting your object identification strategy to reduce reliance on ordinal identifiers.

Performance issues can also arise when tests use ordinal identifiers, particularly in applications with numerous similar objects. In these scenarios, the additional processing required to evaluate ordinal properties can slow down test execution. To mitigate this, optimize your test design by reducing unnecessary object interactions and ensuring your object repository is as efficient as possible.

' Example of troubleshooting a failing ordinal identifier
' Original code that might fail if object order changes
Browser("Page").Page("HomePage").WebList("index:=1").Select "Item"

' Improved approach using multiple properties for more reliable identification
Browser("Page").Page("HomePage").WebList("html tag:=SELECT", "name:=dropdown1").Select "Item"

' Example of using conditional statements to handle dynamic scenarios
Set myList = Browser("Page").Page("HomePage").WebList("name:=dynamic_list")
If myList.Exist(2) Then  ' Wait up to 2 seconds for the object
    If myList.GetROProperty("items") > 0 Then
        myList.Select "Item"
    Else
        Reporter.ReportEvent micWarning, "List empty", "The dynamic list contains no items"
    End If
Else
    Reporter.ReportEvent micFail, "List not found", "Could not locate the dynamic list"
End If

Ordinal Identifiers in Different Environments

While the basic principles of ordinal identifiers apply across different testing environments, their implementation and effectiveness can vary depending on the technology stack you're working with. For web applications, ordinal identifiers are particularly useful when dealing with dynamically generated content, AJAX-based interfaces, or complex data tables. In Windows applications, they can help distinguish between controls in dialog boxes or menu items that share identical properties.

For mobile testing with UFT, ordinal identifiers play a crucial role in identifying elements in mobile applications, especially when dealing with native controls that may lack unique identifiers. Mobile environments often present challenges with object identification due to screen size variations and dynamic UI elements, making ordinal identifiers an essential tool in your testing arsenal.

When working with Java applications, ordinal identifiers can help identify objects in complex Swing or JavaFX interfaces where multiple instances of the same component type may exist. Similarly, in .NET applications, they can be valuable for distinguishing between controls in dynamically generated forms or data grids.

Integrating Ordinal Identifiers with Test Design Strategies

Effective use of ordinal identifiers goes hand in hand with sound test design principles. When designing your tests, consider how object identification strategies impact test maintainability and reliability. One approach is to implement a tiered identification strategy, where you first attempt to identify objects using unique properties, then fall back to ordinal identifiers only when necessary.

Another consideration is the use of object repositories versus descriptive programming. When working with ordinal identifiers, descriptive programming often provides more flexibility, as it allows you to dynamically specify ordinal identifier values based on test conditions or data. However, for applications with relatively stable UI structures, a well-organized object repository that incorporates ordinal identifiers can offer better maintainability.

' Example of using descriptive programming with ordinal identifiers
' Dynamic approach based on test data
Dim testData
testData = DataTable("ItemID", dtLocalSheet)

' Construct object description with dynamic ordinal identifier
Set objDesc = Description.Create()
objDesc("micclass").Value = "WebList"
objDesc("name").Value = "itemList"
objDesc("index").Value = CInt(testData) - 1  ' Convert to zero-based index

' Use the description to get the object
Set myList = Browser("title:=.*Example.*").Page("title:=.*Example.*").ChildObjects(objDesc)(0)

If myList.Exist(2) Then
    myList.Select "Item " & testData
Else
    Reporter.ReportEvent micFail, "List not found", "Could not locate list with index " & testData
End If

Performance Considerations with Ordinal Identifiers

While ordinal identifiers are essential for reliable object identification, they can impact test performance if not used judiciously. Each time UFT evaluates an ordinal identifier, it must potentially scan through multiple objects to find a match, which can slow down test execution, especially in applications with numerous similar elements.

To optimize performance when using ordinal identifiers, consider the following strategies:

1. Minimize the use of location-based identifiers, as they require UFT to evaluate spatial relationships between objects

2. Use index-based identifiers for collections of similar objects, as they're generally more efficient

3. Implement error handling to avoid unnecessary object searches when objects don't exist

4. Cache object references when possible to avoid repeated identification

5. Use Exist statements with appropriate timeouts to avoid unnecessary waiting

By implementing these performance optimization techniques, you can ensure that your tests remain efficient even when using ordinal identifiers.

Future Trends in Object Identification

As applications continue to evolve with more dynamic UI elements, responsive designs, and complex interactions, object identification strategies must also adapt. Future trends in object identification include increased reliance on AI and machine learning to identify objects based on visual characteristics rather than just properties. However, ordinal identifiers will likely remain a crucial component of object identification strategies, especially for distinguishing between similar elements in complex interfaces.

Another emerging trend is the integration of ordinal identifiers with cross-browser and cross-platform testing frameworks. As testing environments become more diverse, the ability to reliably identify objects across different platforms becomes increasingly important. Ordinal identifiers, when used thoughtfully, can provide this consistency across diverse testing environments.

Conclusion

In the comprehensive landscape of object identification in UFT, ordinal identifiers stand as a crucial fallback mechanism that ensures test reliability even in complex scenarios. By understanding what ordinal identifiers are, when they're needed, and how to implement them effectively, you can create automated tests that maintain their accuracy despite application changes. While ordinal identifiers should be used judiciously and in combination with other identification methods when possible, they provide an essential safety net when standard properties prove insufficient.

As you continue to develop your UFT testing skills, remember that thoughtful implementation of ordinal identifiers, coupled with regular maintenance and documentation, will significantly enhance the robustness and maintainability of your automated test suite. By mastering both conventional and ordinal identification methods, you'll be better equipped to build resilient tests that deliver consistent results across various testing scenarios, ultimately improving the quality and reliability of your automated testing efforts.

Frequently Asked Questions

  • What are ordinal identifiers in UFT?
    Ordinal identifiers are fallback mechanisms that assign numerical values to objects based on their position or order within a container or window. They're used when standard identification properties fail to uniquely identify elements.
  • When should I use ordinal identifiers in UFT?
    Use ordinal identifiers when multiple objects share identical properties, such as repeated list items in a data grid, multiple buttons with identical text, or dynamic elements that change positions but maintain similar characteristics.
  • What are the different types of ordinal identifiers in UFT?
    UFT provides location identifiers (based on x,y coordinates), index identifiers (sequential numbers in a collection), and creation time identifiers (when objects were created during runtime). Each serves different identification scenarios.
  • How can I implement ordinal identifiers in my UFT test scripts?
    You can implement ordinal identifiers manually by specifying them as additional properties in object descriptions, or configure UFT to learn them automatically through Object Identification settings. Examples include using 'index:=3' or 'x:=120;y:=80' in your code.
  • What are the best practices for using ordinal identifiers in UFT?
    Use ordinal identifiers sparingly, combine them with other properties when possible, document your usage for future maintenance, and regularly review tests that rely heavily on ordinal identifiers to ensure reliability.

No comments:

Post a Comment