OXYGEN
HomeGitHubReleasesCommunity
  • Welcome to Oxygen
  • About
    • What is Oxygen?
    • Getting Started (Videos)
      • Oxygen IDE Controls Overview
      • Recording a Web Test
      • Oxygen Commands Explained
    • Getting help
  • Download and work with Oxygen
    • Download & Installation
      • Oxygen IDE Installation
      • Oxygen for Mobile Installation
      • Oxygen for Windows Desktop Automation Setup
      • Oxygen for Mac Installation
        • Mac Installation Troubleshooting
      • Oxygen CLI Installation
      • Java Installation Instructions
      • Recording Troubleshooting
    • Start working with Oxygen
      • Getting Started - Web
        • Introduction - Web Testing
        • Recording a Web Test
        • Creating a Web Test
        • Sample Project - Web Test
      • Getting Started - Mobile
        • Introduction - Mobile Testing
        • Recording a Test on Mobile
        • Creating a Test - Mobile
        • Sample Project - Mobile
      • Getting Started - Oxygen for Windows Desktop Automation
      • Getting Started- Oxyge CLI
        • Running a Test Script on Windows
        • Running Multiple Tests (Suites) on Windows
    • Oxygen Modules
      • assert
      • date
      • db
      • email
      • eyes
      • http
      • log
      • mailinator
      • mob
      • pdf
      • proxy
      • serial
      • shell
      • soap
      • twilio
      • utils
      • web
      • win
    • Test Parameters
  • Cloud Providers
    • Sauce Labs
    • Lambda Test
    • TestObject
  • Advanced programming in Oxygen
    • Project Configuration
    • Locating Elements
    • Page Objects
    • Environments
    • Code Components
Powered by GitBook
On this page
  • Locating UI Elements
  • Locator Types

Was this helpful?

  1. Advanced programming in Oxygen

Locating Elements

PreviousProject ConfigurationNextPage Objects

Last updated 4 years ago

Was this helpful?

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 for more details.

  • Insert Locators Manually - choose and insert element locators manually in your Oxygen script, using UI element inspection tools like , 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 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

id=

Locates elements by the value of the id attribute.

Name

name=

Locates elements by the value of the name attribute.

Link

link=

Locates elements by the text in A (anchor) HTML tag.

CSS Selector

css=

Locates elements via the driver’s underlying W3 CSS Selector engine.

XPath

xpath=

Locates elements by XPath.

Mobile Locator Types

Locator

Prefix

Usage

ID

id=

Locates elements by their unique identifier - resource-id attribute for android and name attribute for iOS.

Class

class=

Locates elements by the full name of UI element's class.

Text

text=

Locates elements by their visible text.

XPath

xpath=

Locates elements by XPath.

Here are some usage examples:

web.click('id=submit') // ID

web.type('name=firstNameInput', 'first name') // Name

web.click('https://link.com') // Link

web.click('div > button.login') // CSS Selector

web.select('//select[@id="selectGender"]', 'label=female') // XPath

See for more locator types and additional details.

See for more locator types and additional details.

Web Recording Guide
Chrome DevTools
Mobile Recording Guide
Web Module (web)
Mobile Module (mob)