Locating Elements
Locating UI Elements
Automated UI tests (either web or mobile), are mostly focused on performing certain actions on page's or screen's elements. One of the key challenges in writing UI tests is correctly identifying elements on the screen. Accurate element identification is very important to have stable automation tests.
If the elements are incorrectly identified, the test will misbehave and perform actions on wrong elements or just fail, not able to find any. This is called test flakiness. To prevent or minimize flaky tests, you have to make sure the UI elements are uniquely identified.
Selenium and Oxygen use locators
to identify UI elements. Most of Oxygen commands in web
and mob
modules require a locator to perform various actions on the element (such as find an element, assert element's value, etc.). Oxygen provides a wide variety of locator types (strategies) which help to identify elements by different attributes and hierarchical position.
Oxygen allows you to either generate locators automatically or write them manually using various element inspection tools. Here is what you can do:
Use Oxygen IDE Recorder - Oxygen IDE can record Chrome browser based user interactions and generate all possible locators for the selected element. Oxygen IDE will also pre-select the most suitable locator for the specific object. See Web Recording Guide for more details.
Insert Locators Manually - choose and insert element locators manually in your Oxygen script, using UI element inspection tools like Chrome DevTools, Appium Desktop, etc.
Note: In order to record mobile application actions and locators, you will need to use a special version of Appium Desktop that supports generating Oxygen code. See Mobile Recording Guide for more details.
Locator Types
Oxygen provides different locator types to help to identify UI elements of web and mobile applications. To indicate which locator type to use, the locator
parameter shall start with type prefix
. Below are various locator types and prefixes for web and mobile applications.
Web Locator Types
Locator | Prefix | Usage |
ID |
| Locates elements by the value of the |
Name |
| Locates elements by the value of the |
Link |
| Locates elements by the text in A (anchor) HTML tag. |
CSS Selector |
| Locates elements via the driver’s underlying W3 CSS Selector engine. |
XPath |
| Locates elements by XPath. |
See Web Module (web) for more locator types and additional details.
Mobile Locator Types
Locator | Prefix | Usage |
ID |
| Locates elements by their unique identifier - |
Class |
| Locates elements by the full name of UI element's class. |
Text |
| Locates elements by their visible text. |
XPath |
| Locates elements by XPath. |
See Mobile Module (mob) for more locator types and additional details.
Here are some usage examples:
Last updated