Our engine is using Appium to locate the elements in Mobile Applications.
The different locators are as follows:
- Accessibility ID
- Class Name
- Text Inside
- Android UI Automator
- iOS UI Automation
Know your locators
|Accessibility ID||Read a unique identifier for a UI element. For iOS it's the accessibility-id attribute. For Android it is the element's content-desc attribute.|
|Class Name||For iOS it is the full name of the XCUI element and begins with XCUIElementType. For Android it is the full name of the UIAutomator2 class (e.g.: android.widget.TextView)|
|ID||Native element identifier. resource-id for android; name for iOS.|
|Name||Name of element|
|Text Inside||Search for element by using the value of the text attribute.|
|XPath||Search the app XML source using xpath (not recommended, has performance issues)|
|Coordinates||Search for element by using Coordinates, only available for touch actions.|
|Android UI Automator||Use the UI Automator API, in particular the UiSelector class to locate elements. In Appium you send the Java code, as a string, to the server, which executes it in the application's environment, returning the element or elements.|
|IOS UI Automation||When automating an iOS application, Apple's Instruments framework can be used to find elements|
Even if you are using our Endtest Element Inspector to locate your elements, you might still encounter situations where you need to fetch a locator.
But what can you do if you're getting an error message that the element could not be found?
Tips and Tricks:
1. Make sure that your locator is unique.
If our engine finds more than one element with that locator, it will just go with the first one, which might not be the one you're interested in.
2. Try to use a different locator type.
For example, if you were using ID, you can try with XPath or Accessibility ID.
3. Are you testing a Hybrid Mobile Application?
Hybrid Mobile Applications have a Native Context and a Web context, you need to switch to a context before you can access the elements which are inside it.
You can use the
Get List of Contexts,
Get Current Context and
Switch to Context actions to achieve that.
Since you cannot perform Touch Actions on elements which are in the Web Context, you need to extract their coordinates while you're in the Web Context and then switch back to the Native Context and perform the Touch Actions by using those coordinates.
4. How do I get the locators for the elements from my Mobile Application?
The easiest way would be to add a
Get Element Inspector step in your test, that will generate a HTML file from which you can extract the locators.
The other option is to add a
Get Page Source step in your test.
If you're testing a Hybrid Mobile App, you will get the page source that is tied to your current context, you can switch between contexts to get all the page sources.
We strongly recommend that you read more about finding elements with Appium here.
5. Try to identify what makes the element unique.
Or if you only want to add a part of the value from the attribute:
And you can also write an XPath which uses multiple attributes:
//*[@attribute_1 = "attribute_value_1" and @attribute_2 = "attribute_value_2" ]
To narrow the search, you can also mention the type of the element in the XPath:
For example, if you're targeting the element of type
android.widget.ImageButton with the
content-desc attribute that has the value