In automated mobile testing, targeting the correct element can be challenging: mobile apps are dynamic, and sometimes target elements lack unique, descriptive attributes. To address this challenge, mabl provides a variety of mobile find methods so that tests interact with the correct elements during execution. This article outlines how to use mabl’s find methods to create more reliable mobile test steps.
Find elements by native attributes
When you record interactions with your mobile app, the Trainer collects details about the target element’s native attributes from the page source, such as “class” or “text”. During execution, mabl uses these tracked attributes to find a matching element.
Configure Find
If the target element is very similar to other page elements, or if its native attributes have dynamic values, update the step to use Configure Find. With Configure Find, you can:
- Specify which element attributes mabl should look for
- Set a timeout to define how long mabl should look for the element.
Element description
For tap steps, mabl also automatically captures an element description, which describes the visual appearance of the target element. During execution, if native text-based attributes such as class or text aren’t enough to reliably target the element, mabl uses the element description to locate the target element instead.
By default, element descriptions are generated in English. Workspace owners may configure them to be generated in a different language on the Workspace page: Settings > Workspace.
Target a visual area of the page
When interacting with highly visual elements or elements that lack unique native attributes, you can also create tap steps that target a visual area of the page. Visual training is helpful for recording steps that interact with images, maps, and canvas elements. See the article on visual training for taps and clicks for more details.
Reselect the element
If Configure Find and element descriptions fail to reliably target the element, try reselecting an alternative target element that is more unique. For example, if your test fails to tap the correct button on the screen, there may be a child element within the button that contains a more unique attribute, such as text.
To reselect the target element for a test step, launch the test in the Trainer, get your application in the correct state, and take the following steps:
- Hover your mouse over the step that isn’t targeting the correct element.
- Click on the edit pencil.
- Click on the Reselect button. The mabl Trainer adds an overlay to the application under test.
- Hover your mouse over elements in the application to view their attributes.
- Select an alternative element that has more unique attributes and accomplishes the same intended action. If it’s difficult to target the desired element, press shift and use the up and down arrows to scroll through overlapping elements at your mouse position until it highlights the element you want to select.
- Click OK to update the target element for the step.
Reselecting an element
Improve element findability
mabl’s find strategy adapts based on the information that we get for the application under test. The more consistent and unique an attribute is, the more helpful it is for element findability.
If you are unable to create a successful find step using the native attributes, Configure Find, or visual training, ask the developers on your team about making changes to improve element findability. A common approach is to add accessibility IDs or resource IDs to key elements, based on your application type.
The debug view
When you talk to your developers about the challenges you’re facing when interacting with the target element, consider using the debug view in the mabl Trainer as a resource. The debug view is a diagnostic tool that you can use to understand target element attributes in isolation and in context. Learn more.
Find by XPath
If mabl fails to identify the correct element and your developers cannot add more unique attributes to the elements, consider enabling “Find by XPath” as a last resort.
Unlike standard recorded steps, which use a range of strategies to target the correct element, “Find by XPath” identifies the target element only using XPath. If you enable “Find by XPath”, keep in mind the following:
- The recorded XPath cannot be edited.
- “Find by XPath” is more brittle. If there are any changes in your application, the step may fail and you’ll have to retrain the interaction.
To enable “Find by XPath”, take the following steps:
- Hover your mouse over the step that isn’t targeting the correct element.
- Click on the edit pencil.
- Check the box for “Find by XPath”
- Click OK to update the step.