Element Key Features

Note

Here you will find information on complex or ambiguous functionality. For a comprehensive list of all available methods, please refer to the Element Interface documentation.


1. Delayed Element initialization:

Important

Following information suitable for Element object, that defined as class attribute of Page or Group

Key functionality:

  • Elements are initialized based on the current driver. If no driver is available, the element will be initialized later within the Page or Group class initialisation.

  • The driver and driver_wrapper will sets to Element object automatically from Page or Group instances



2. Custom waits

The waiting methods for Selenium and Appium have been reworked to improve efficiency, particularly for negative checks (i.e., when an element is not present on the page).

Key changes:

  • Reduced implicitly_wait: The default implicitly_wait time in Selenium and Appium has been reduced. This adjustment is made because Selenium’s implicitly_wait tends to cause long delays when checking for elements that are not present on the page.

  • Internal Waiting Mechanism: Instead of relying on Selenium’s or Appium’s native waiting strategies, all waiting methods now use internal methods with built-in Python loops. This allows for more precise control over the waiting time and conditions, leading to faster and more reliable checks.



3. Built-in waits

Most methods automatically wait for specific element states. For example, the framework will wait until a web element becomes clickable before executing click method on it.



4. Original locator preservation

The source_locator attribute stores the original locator exactly as it was provided to Element.__init__, before any platform-specific resolution or framework-specific transformations.

Note

For static sub-elements, consider using the built-in parent mechanism instead — Element objects defined as class attributes of a Group automatically search within the Group locator (see Group documentation).

source_locator is designed for cases where you need the raw locator string for dynamic XPath construction at runtime — something the parent mechanism cannot do.

Example — dynamic table parsing:

from mops.base.group import Group
from mops.base.element import Element


class DataTable(Group):

    def load(self):
        row_locator = f'{self.source_locator}//tr'
        row_elements = Element(row_locator, f'{self.name}: Rows').all_elements

        self.rows = []
        for index, _ in enumerate(row_elements):
            cell_locator = f'({row_locator})[{index + 1}]/td'
            cells = Element(cell_locator, f'{self.name}: Row {index} cells')
            self.rows.append(cells)

Here source_locator is used to dynamically compose new XPath expressions via string concatenation. This cannot be achieved with the parent mechanism because:

  • The XPath grouping operator (…)[n] requires building the full expression as a single string.

  • New Element objects are created at runtime, not as class-level attributes.

  • After initialization, locator is transformed with platform prefixes (e.g., xpath= for Playwright), making it unsuitable for string concatenation.

Note

source_locator preserves the exact type passed in: if a Locator dataclass was given, it stays a Locator; if a string was given, it stays the original string. The locator attribute, by contrast, is resolved to a platform-specific string and may be further modified (e.g., prefixed with xpath= for Playwright or converted to a CSS selector for ID-based locators in Selenium).