Locator dataclass

Overview

The Locator class is designed to provide a flexible mechanism for managing locators in a unified way. This class supports different locator types for various platforms and devices, including desktop, mobile, and tablet environments. The Locator class is particularly useful in automation frameworks where locators need to be adapted based on the specific driver and capabilities being used.

This object and its usage aim to reduce the redundancy of creating multiple attributes for different platforms. By centralizing locators in a single Locator object, it simplifies the codebase and enhances maintainability.


Interface

class mops.mixins.objects.locator.Locator(default: str | None = None, desktop: str | None = None, mobile: str | None = None, tablet: str | None = None, ios: str | None = None, android: str | None = None)[source]

Represents a WEB UI element locator with platform-specific variations.

default: str | None = None

The default locator for the object, used by default if no other locators are specified or if no specific platform/device type is detected.

Type:

All

desktop: str | None = None

The locator for desktop environments, typically used for browsers on desktop platforms.

Type:

All

mobile: str | None = None

The locator for general mobile environments, used for mobile platforms other than iOS and Android, as well as for mobile resolutions of desktop browsers.

Type:

All

tablet: str | None = None

The locator specifically for tablet devices, useful for web and app automation on tablets. The “is_tablet: True” desired_capability is required.

Type:

Appium only

ios: str | None = None

The locator specifically for iOS devices, allowing for targeting locators specific to iOS applications.

Type:

Appium only

android: str | None = None

The locator specifically for Android devices, allowing for targeting locators specific to Android applications.

Type:

Appium only


Usage

The Locator class is designed to be flexible and adaptive, making it suitable for various automation scenarios. Here’s how the attributes work together:

  • loc_type is optional. If not specified, the system will attempt to automatically select the appropriate locator type based on the provided locator.

  • default will be used if no specific locator is provided for the current platform or device.


Example

# Providing string parameter instead of Locator object
button = Element('.button', name='button')

search_button = Element(Locator(desktop='.search', mobile='.mobile.search'), name='search button')