Many applications contain dynamic UI elements. These elements change whenever a particular event happens, such as a web page reload. Automated testing tools often struggle to identify these elements reliably because robust identifiers for static UI elements (like the element ID) change constantly. To solve this, you must use alternative identifiers for dynamic UI elements.
For web elements, Ranorex Studio uses an intelligent algorithm that recognizes dynamic UI elements. It ignores dynamic IDs and selects robust, static attributes instead. In most cases, you do not need to manually find or replace dynamic IDs in your web repository items.
However, for desktop and mobile applications, you must manage dynamic IDs manually. You can either edit the RanoreXPaths of your repository items by hand or use RanoreXPath weight rules to optimize object recognition.
This chapter explains how attribute weights work and how you can change them with weight rules so Ranorex Studio identifies dynamic UI elements reliably.
The object recognition process
When tracking and identifying UI elements, Ranorex Studio categorizes them according to their purpose and to define their states. The categorization reflects when a UI element is dynamic—for example, when an attribute contains a dynamic value.
The following process illustrates how Ranorex Studio categorizes elements:
- Assignment of technology-independent role
- Assignment of role-specific characteristics…
- …and attributes derived from these characteristics
- Assignment of one or more technology-specific capabilities…
- …and attributes derived from these capabilities
UI element identification with RanoreXPath
Ranorex Studio uses RanoreXPath expressions to identify UI elements. These expressions are based on a set of hierarchical nodes and predicates. They reflect the categories assigned in the object recognition process. Therefore, a RanoreXPath expression may contain a dynamic attribute value to identify a UI element.
The following image shows the structure of the RanoreXPath expression for the Exit button in the Ranorex Studio Demo Application. The expression uses a stable attribute value to identify the button.
- Basic structure: The RanoreXPath for an isolated UI element consists of three elements: an axis specifier, a node, and zero or more predicate(s)
- For the isolated Exit button, the axis specifier is /, the node is the role button, and the predicate consists of an attribute-value pair that uniquely identifies the button
UI element identification with RanoreXPath
Ranorex Studio identifies UI elements using RanoreXPath expressions. These expressions rely on hierarchical nodes and predicates that reflect the categories assigned during the object recognition process. Consequently, a RanoreXPath expression might include a dynamic attribute value.
The following image shows the structure of the RanoreXPath expression for the Exit button in the Ranorex Studio Demo Application. The expression uses a stable attribute value to identify the button.
- Basic structure: The RanoreXPath for an isolated UI element consists of three elements: an axis specifier, a node, and zero or more predicate(s)
- For the isolated Exit button, the axis specifier is
/, the node is the role button, and the predicate consists of an attribute-value pair that uniquely identifies the button
Which attributes does the RanoreXPath use?
Ranorex Studio first categorizes UI elements and then generates a RanoreXPath expression for them based on these categories. While an element usually has only one role, it possesses many attributes derived from its various categories and capabilities. Attribute weights determine which of these attributes Ranorex Studio selects for the RanoreXPath expression.
Example: Exit button in the Demo App.
- Ranorex Studio assigns the technology-independent role button to the UI element.
- Ranorex Studio identifies the element as a WinForms element and assigns the technology-specific capability WinForms.
- The WinForms capability offers four Control attributes. Ranorex Studio selects ControlName for the RanoreXPath.
Ranorex Studio does not choose ControlName randomly; it selects this attribute because it has the highest weight among the available options.
Attribute weights are important because they allow you to tell Ranorex Studio to use a stable attribute to identify a UI element. This ensures the reliable identification of dynamic UI elements.