Sometimes it is useful to have a single repository item represent multiple UI elements. Typical examples include groups of similar controls, such as radio buttons or checkboxes. This pattern is most commonly used in code modules.
Necessary context
The concept covered in this chapter is often used with code modules, which is an expert topic. In addition, you will find the example easier to understand if you are familiar with the RanoreXPath syntax and the Ranorex Spy tool. Use the links below to learn more about these topics:
Example definition
In the following example, one repository item represents two radio buttons. These radio buttons appear in the gender selection region of the Test database tab in the Demo Application.
Track the repository item
The procedure for creating a repository item to represent multiple elements is the same as for a regular repository item. Refer to the instructions below:
- Open Ranorex Spy
- Start the Demo Application and click Test database tab
- Track one of the gender selection radio buttons
- Tracked and identified female radio button UI element in the Demo Application
- Unique RanoreXPath specification for the female radio button in Ranorex Spy
- UI element browser tree displaying the defined path for the female radio button in Ranorex Spy
- Path editor for the female radio button in Ranorex Spy
Generalize the RanoreXPath specification
Follow the steps below to generalize the RanoreXPath specification so that it includes the second gender selection radio button of the demo application.
- In Ranorex Spy, open the Path editor for the tracked radio button.
- Identify the part of the RanoreXPath that distinguishes the first radio button from the second one (for example, a specific attribute value or index).
- Generalize this part of the path so that the RanoreXPath matches both radio buttons.
- Apply the change and run a search in Ranorex Spy to verify that both radio buttons are found.
The image below shows an example of how an initial RanoreXPath that matches only the female radio button is modified into a generalized RanoreXPath that matches both radio buttons.
- Initial RanoreXPath specification that includes only the female radio button
-
Modified, generalized RanoreXPath specification that includes both radio buttons
Multiple repository items detection
After you generalize the RanoreXPath specification, Ranorex Spy finds both gender selection radio buttons with the same path.
- Positive match of two tracked radio buttons
- Ranorex Spy displays the match result in the lower-left corner of the working environment
Add the tracked item to the repository
Finally, add the matched items to the repository.
- In Ranorex Spy, select one of the matching UI elements.
- Right-click it and select Add to repository.
Name the generalized repository item
Like all repository items, the generalized repository item can be renamed to be more meaningful.
- Select the repository item representing multiple UI elements.
- Open the context menu to change the repository item name.