Element Interface

Warning

This is auto-generated interface documentation for the abstract Element class.

This is essential for providing a comprehensive overview of all available methods for the Element object.

For the actual signature, please refer to mops.base.element.Element.

Note

All of these methods will work in the same way for Group class instances, which represent a collection of elements.

The Element class is a fundamental building block for creating Page Object Models (POM) in web testing. It provides a comprehensive set of methods that allow you to interact with various web page elements which be found below.


class mops.base.element.Element(*args: Any, **kwargs: Any)[source]

Represents a UI element that serves as a central component for interaction.

The Element class is designed to be used within Page or Group objects.

It dynamically adapts to different driver types (Playwright, Appium, Selenium) and provides a unified interface for UI interactions.

__init__(locator: Locator | str, name: str = '', parent: Group | Element | bool = None, wait: bool | None = None, driver_wrapper: DriverWrapper | Any = None)[source]

Initialize an Element based on the current driver.

If no driver is available, initialization is skipped and will be handled later in a Page or Group.

Parameters:
  • locator (Union[Locator, str]) – The element’s locator. .LocatorType is optional.

  • name (str) – The name of the element, used for logging and identification purposes.

  • parent (Union[Group, Element, bool]) – The parent of the element. Provide False to skip association.

  • wait (Optional[bool]) – If True, the element will be checked in wait_page_loaded and is_page_opened methods of Page.

  • driver_wrapper (Union[DriverWrapper, Any]) – The DriverWrapper instance or an object containing it to be used for this element.

property driver_wrapper: DriverWrapper

Retrieves the driver wrapper instance.

Returns:

The current DriverWrapper instance that assigned for this object.

Return type:

DriverWrapper

source_locator: Locator | str
name: str
parent: Any | bool | None
wait: bool | None
property locator: str

Return the element locator string.

property locator_type: str

Return the element locator type.

property log_locator: str

Return the element locator string for logging.

set_text(text: str, silent: bool = False) Element[source]

Clear the current input field and type the provided text.

Parameters:
  • text (str) – The text to enter into the element.

  • silent (bool) – If True, suppresses logging.

Returns:

Element

send_keyboard_action(action: str | KeyboardKeys) Element[source]

Send a keyboard action to the current element (e.g., press a key or shortcut).

Parameters:

action (str or KeyboardKeys) – The keyboard action to perform.

Returns:

Element

wait_visibility(*, timeout: int = 10, silent: bool = False, continuous: bool | float = False) Element[source]
Wait until the element becomes visible.

Note: The method requires the use of named arguments.

A continuous visibility verification may be applied for given or default amount of time after the first condition is met.

Selenium:

  • Applied wait_condition() decorator integrates a 0.1 seconds delay for each iteration during the waiting process.

Appium:

  • Applied wait_condition() decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.

Parameters:
  • timeout (int) – The maximum time to wait for the condition (in seconds). Default: WAIT_EL.

  • silent (bool) – If True, suppresses logging.

  • continuous (Union[int, float, bool]) – If True, a continuous visibility verification applied for another 2.5 seconds. An int or float modifies the continuous wait timeout.

Returns:

Element

wait_visibility_without_error(*, timeout: float = 2.5, silent: bool = False, continuous: bool | float = False) Element[source]
Wait for the element to become visible, without raising an error if it does not.

Note: The method requires the use of named arguments.

A continuous visibility verification may be applied for given or default amount of time after the first condition is met.

Selenium & Playwright:

  • Applied wait_condition() decorator integrates a 0.1 seconds delay for each iteration during the waiting process.

Appium:

  • Applied wait_condition() decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.

Parameters:
  • timeout (Union[int, float]) – The maximum time to wait for the condition (in seconds). Default: QUARTER_WAIT_EL.

  • silent (bool) – If True, suppresses logging.

  • continuous (Union[int, float, bool]) – If True, a continuous visibility verification applied for another 2.5 seconds. An int or float modifies the continuous wait timeout.

Returns:

Element

wait_hidden(*, timeout: int = 10, silent: bool = False, continuous: bool | float = False) Element[source]
Wait until the element becomes hidden.

Note: The method requires the use of named arguments.

A continuous invisibility verification may be applied for given or default amount of time after the first condition is met.

Selenium:

  • Applied wait_condition() decorator integrates a 0.1 seconds delay for each iteration during the waiting process.

Appium:

  • Applied wait_condition() decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.

Parameters:
  • timeout (int) – The maximum time to wait for the condition (in seconds). Default: WAIT_EL.

  • silent (bool) – If True, suppresses logging.

  • continuous (Union[int, float, bool]) – If True, a continuous invisibility verification applied for another 2.5 seconds. An int or float modifies the continuous wait timeout.

Returns:

Element

wait_hidden_without_error(*, timeout: float = 2.5, silent: bool = False, continuous: bool | float = False) Element[source]
Wait for the element to become hidden, without raising an error if it does not.

Note: The method requires the use of named arguments.

A continuous invisibility verification may be applied for given or default amount of time after the first condition is met.

Selenium & Playwright:

  • Applied wait_condition() decorator integrates a 0.1 seconds delay for each iteration during the waiting process.

Appium:

  • Applied wait_condition() decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.

Parameters:
  • timeout (Union[int, float]) – The maximum time to wait for the condition (in seconds). Default: QUARTER_WAIT_EL.

  • silent (bool) – If True, suppresses logging.

  • continuous (Union[int, float, bool]) – If True, a continuous invisibility verification applied for another 2.5 seconds. An int or float modifies the continuous wait timeout.

Returns:

Element

wait_availability(*, timeout: int = 10, silent: bool = False) Element[source]
Wait until the element becomes available in DOM tree. n

Note: The method requires the use of named arguments.

Selenium:

  • Applied wait_condition() decorator integrates a 0.1 seconds delay for each iteration during the waiting process.

Appium:

  • Applied wait_condition() decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.

Parameters:
  • timeout (int) – The maximum time to wait for the condition (in seconds). Default: WAIT_EL.

  • silent (bool) – If True, suppresses logging.

Returns:

Element

wait_for_text(expected_text: str | None = None, *, timeout: float = 10, silent: bool = False) Element[source]

Wait for the presence of a specific text in the current element, or for any non-empty text.

Note: The method requires the use of named arguments except expected_text.

Selenium & Playwright:

  • Applied wait_condition() decorator integrates a 0.1 seconds delay for each iteration during the waiting process.

Appium:

  • Applied wait_condition() decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.

Parameters:
  • expected_text (Optional[str]) – The text to wait for. None - any text; str - expected text.

  • timeout (Union[int, float]) – The maximum time to wait for the condition (in seconds). Default: WAIT_EL.

  • silent (bool) – If True, suppresses logging.

Returns:

Element

wait_for_value(expected_value: str | None = None, *, timeout: float = 10, silent: bool = False) Element[source]

Wait for a specific value in the current element, or for any non-empty value.

Note: The method requires the use of named arguments except expected_value.

Selenium & Playwright:

  • Applied wait_condition() decorator integrates a 0.1 seconds delay for each iteration during the waiting process.

Appium:

  • Applied wait_condition() decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.

Parameters:
  • expected_value (Optional[str]) – The value to waiting for. None - any value; str - expected value.

  • timeout (Union[int, float]) – The maximum time to wait for the condition (in seconds). Default: WAIT_EL.

  • silent (bool) – If True, suppresses logging.

Returns:

Element

wait_enabled(*, timeout: float = 10, silent: bool = False) Element[source]

Wait for the element to become enabled and/or clickable.

Note: The method requires the use of named arguments.

Selenium & Playwright:

  • Applied wait_condition() decorator integrates a 0.1 seconds delay for each iteration during the waiting process.

Appium:

  • Applied wait_condition() decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.

Parameters:
  • timeout (Union[int, float]) – The maximum time to wait for the condition (in seconds). Default: WAIT_EL.

  • silent (bool) – If True, suppresses logging.

Returns:

Element

wait_disabled(*, timeout: float = 10, silent: bool = False) Element[source]

Wait for the element to become disabled.

Note: The method requires the use of named arguments.

Selenium & Playwright:

  • Applied wait_condition() decorator integrates a 0.1 seconds delay for each iteration during the waiting process.

Appium:

  • Applied wait_condition() decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.

Parameters:
  • timeout ([int, float]) – The maximum time to wait for the condition (in seconds). Default: WAIT_EL.

  • silent (bool) – If True, suppresses logging.

Returns:

Element

wait_for_size(expected_size: Size, *, timeout: float = 10, silent: bool = False) Element[source]

Wait until element size will be equal to given Size object

Note: The method requires the use of named arguments except expected_size.

Selenium & Playwright:

  • Applied wait_condition() decorator integrates a 0.1 seconds delay for each iteration during the waiting process.

Appium:

  • Applied wait_condition() decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.

Parameters:
  • expected_size (Size) – expected element size

  • timeout (Union[int, float]) – The maximum time to wait for the condition (in seconds). Default: WAIT_EL.

  • silent (bool) – If True, suppresses logging.

Returns:

Element

wait_elements_count(expected_count: int, *, timeout: float = 10, silent: bool = False) Element[source]

Wait until the number of matching elements equals the expected count.

Note: The method requires the use of named arguments except expected_count.

Selenium & Playwright:

  • Applied wait_condition() decorator integrates a 0.1 seconds delay for each iteration during the waiting process.

Appium:

  • Applied wait_condition() decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.

Parameters:
  • expected_count (int) – The expected number of elements.

  • timeout (Union[int, float]) – The maximum time to wait for the condition (in seconds). Default: WAIT_EL.

  • silent (bool) – If True, suppresses logging.

Returns:

Element

property all_elements: list[mops.base.element.Element] | list[Any]

Return a list of all matching elements.

Returns:

A list of wrapped Element objects.

is_visible(check_displaying: bool = True, silent: bool = False) bool[source]

Check if the current element’s top-left corner or bottom-right corner is visible on the screen.

Parameters:
  • check_displaying (bool) – If True, the is_displayed() method will be called to further verify visibility. The check will stop if this method returns False.

  • silent (bool) – If True, suppresses logging.

Returns:

bool

is_fully_visible(check_displaying: bool = True, silent: bool = False) bool[source]

Check is current element top left corner and bottom right corner visible on current screen

Parameters:
  • check_displaying (bool) – If True, the is_displayed() method will be called to further verify visibility. The check will stop if this method returns False.

  • silent (bool) – If True, suppresses logging.

Returns:

bool

scroll_into_view(block: ScrollTo = 'center', behavior: ScrollTypes = 'instant', sleep: float = 0, silent: bool = False) Element[source]

Scrolls the element into view using a JavaScript script.

Parameters:
  • block (ScrollTo) – The scrolling block alignment. One of the ScrollTo options.

  • behavior (ScrollTypes) – The scrolling behavior. One of the ScrollTypes options.

  • sleep (Union[int, float]) – Delay in seconds after scrolling. Can be an integer or a float.

  • silent (bool) – If True, suppresses logging.

Returns:

Element

save_screenshot(file_name: str, screenshot_base: bytes | Image = None, convert_type: str | None = None) Image[source]

Save a screenshot of the element.

Parameters:
  • file_name (str) – Path or filename for the screenshot.

  • screenshot_base (bytes, PIL.Image.Image) – Screenshot binary or image to use (optional).

  • convert_type (str) – Image conversion type before saving (optional).

Returns:

PIL.Image.Image

hide(silent: bool = False) Element[source]

Make the element invisible by setting its opacity to 0.

Parameters:

silent (bool) – If True, suppresses logging.

Returns:

Element

show(silent: bool = False) Element[source]

Make the element visible by setting its opacity to 1.

Parameters:

silent (bool) – If True, suppresses logging.

Returns:

Element

execute_script(script: str, *args: Any) Any[source]

Execute a JavaScript script on the element.

Parameters:
  • script (str) – JavaScript code to be executed, referring to the element as arguments[0].

  • args (typing.Any) – Any arguments to pass to the JavaScript.

Returns:

typing.Any result from the script.

assert_screenshot(filename: str = '', test_name: str = '', name_suffix: str = '', threshold: float | None = None, delay: float | None = None, scroll: bool = False, remove: Element | list[Element] = None, fill_background: str | bool = False, cut_box: Box = None, hide: Element | list[Element] = None) None[source]

Assert that the given screenshot matches the currently taken screenshot.

Parameters:
  • filename (str) – The full name of the screenshot file. If empty - filename will be generated based on test name & Element name argument & platform.

  • test_name (str) – The custom test name for generated filename. If empty - it will be determined automatically.

  • name_suffix (str) – A suffix to add to the filename. Useful for distinguishing between positive and negative cases for the same Element during one test.

  • threshold (Optional[int, float]) – The acceptable threshold for comparing screenshots. If None - takes default threshold or calculate its automatically based on screenshot size.

  • delay (Optional[int, float]) – The delay in seconds before taking the screenshot. If None - takes default delay.

  • scroll (bool) – Whether to scroll to the element before taking the screenshot.

  • remove (Optional[Element or List[Element]]) – Element to remove from the screenshot. Can be a single element or a list of elements.

  • fill_background (Optional[str or bool]) – The color to fill the background. If True, uses a default color (black). If a str, uses the specified color.

  • cut_box (Optional[Box]) – A Box specifying a region to cut from the screenshot. If None, no region is cut.

  • hide (Optional[Element or List[Element]]) – Element to hide in the screenshot. Can be a single element or a list of elements.

Returns:

None

soft_assert_screenshot(filename: str = '', test_name: str = '', name_suffix: str = '', threshold: float | None = None, delay: float | None = None, scroll: bool = False, remove: Element | list[Element] = None, fill_background: str | bool = False, cut_box: Box = None, hide: Element | list[Element] = None) tuple[bool, str][source]

Compare the currently taken screenshot to the expected screenshot and return a result.

Parameters:
  • filename (str) – The full name of the screenshot file. If empty - filename will be generated based on test name & Element name argument & platform.

  • test_name (str) – The custom test name for generated filename. If empty - it will be determined automatically.

  • name_suffix (str) – A suffix to add to the filename. Useful for distinguishing between positive and negative cases for the same Element during one test.

  • threshold (Optional[int, float]) – The acceptable threshold for comparing screenshots. If None - takes default threshold or calculate its automatically based on screenshot size.

  • delay (Optional[int, float]) – The delay in seconds before taking the screenshot. If None - takes default delay.

  • scroll (bool) – Whether to scroll to the element before taking the screenshot.

  • remove (Optional[Element or List[Element]]) – Element to remove from the screenshot.

  • fill_background (Optional[str or bool]) – The color to fill the background. If True, uses a default color (black). If a str, uses the specified color.

  • cut_box (Optional[Box]) – A Box specifying a region to cut from the screenshot. If None, no region is cut.

  • hideElement to hide in the screenshot. Can be a single element or a list of elements.

Returns:

typing.Tuple (bool, str) - result state and result message

check() Element

Check the checkbox element.

Returns:

Element

clear_text(silent: bool = False) Element

Clear the text of the element.

Parameters:

silent (bool) – If True, suppresses logging.

Returns:

Element

click(*, force_wait: bool = True, **kwargs: Any) Element

Clicks on the element.

Parameters:

force_wait (bool) – If True, waits for element visibility before clicking.

Selenium/Appium:

Selenium Safari using js click instead.

Parameters:

kwargs – compatibility arg for playwright

Playwright:

Parameters:

kwargsany kwargs params from source API

Returns:

Element

click_in_alert() Element

Perform a click on an element inside an alert box (Mobile only). Note: Automatically switches to native context of the browser.

Returns:

Element

click_into_center(silent: bool = False) Element

Clicks at the center of the element.

Parameters:

silent (bool) – If True, suppresses logging.

Returns:

Element

click_outside(x: int = -5, y: int = -5) Element

Perform a click outside the current element, by default 5px left and above it.

Parameters:
  • x (int) – Horizontal offset from the element to click.

  • y (int) – Vertical offset from the element to click.

Returns:

Element

property driver: SeleniumWebDriver | AppiumWebDriver | PlaywrightSourcePage

Retrieves the source driver instance, which could be a Selenium, Appium, or Playwright driver.

Returns:

Current source driver that assigned for this object, which is either n selenium.webdriver.remote.webdriver.WebDriver orn appium.webdriver.webdriver.WebDriver orn playwright.sync_api.Page instance.

property element: SeleniumWebElement | AppiumWebElement | PlayWebElement

Returns a source element object, depending on the current driver in use.

Returns:

selenium.webdriver.remote.webelement.WebElement orn appium.webdriver.webelement.WebElement orn playwright.sync_api.Locator

get_all_texts(silent: bool = False) list[str]

Retrieve text content from all matching elements.

Parameters:

silent (bool) – If True, suppresses logging.

Returns:

list of str - A list containing the text content of all matching elements.

get_attribute(attribute: str, silent: bool = False) str

Retrieve a specific attribute from the current element.

Parameters:
  • attribute (str) – The name of the attribute to retrieve, such as ‘value’, ‘innerText’, ‘textContent’, etc.

  • silent (bool) – If True, suppresses logging.

Returns:

str - The value of the specified attribute.

get_element_info(element: Element | None = None) str[source]

Retrieve detailed logging information for the specified element.

Parameters:

element (Element or None) – The Element for which to collect logging data. If None, logging data for the parent element is used.

Returns:

str - A string containing the log data.

get_elements_count(silent: bool = False) int

Get the count of matching elements.

Parameters:

silent (bool) – If True, suppresses logging.

Returns:

int - The number of matching elements.

get_rect() dict

Retrieve the size and position of the element as a dictionary.

Returns:

dict - A dictionary {‘x’, ‘y’, ‘width’, ‘height’} of the element.

hover(silent: bool = False) Element

Hover the mouse over the current element.

Parameters:

silent (bool) – If True, suppresses logging.

Returns:

Element

hover_outside(x: int = 0, y: int = -5) Element

Hover the mouse outside the current element, by default 5px above it.

Parameters:
  • x (int) – Horizontal offset from the element to hover.

  • y (int) – Vertical offset from the element to hover.

Returns:

Element

property inner_text: str

Returns the inner text of the element.

Returns:

str - element inner text

is_available() bool

Check if the element is available in DOM tree.

Returns:

bool - True if present in DOM

is_checked() bool

Check if a checkbox or radio button is selected.

Returns:

bool - True if the checkbox or radio button is checked, False otherwise.

is_displayed(silent: bool = False) bool

Check if the element is displayed.

Parameters:

silent (bool) – If True, suppresses logging.

Returns:

bool

is_enabled(silent: bool = False) bool

Check if the current element is enabled.

Parameters:

silent (bool) – If True, suppresses logging.

Returns:

bool - True if the element is enabled, False otherwise.

is_hidden(silent: bool = False) bool

Check if the element is hidden.

Parameters:

silent (bool) – If True, suppresses logging.

Returns:

bool

property location: Location

Get the location of the current element, including the x and y coordinates.

Returns:

Location - An object representing the element’s position.

log(message: str, level: str = 'info') None

Log a message with detailed context in the following format:

# Format
[time][level][driver_index][module][function:line] <message>
# Example
[Aug 14][16:04:22.767][I][2_driver][play_element.py][is_displayed:328] Check visibility of "Mouse page"
Parameters:
  • message (str) – The log message to record.

  • level (str) – The logging level, which should be one of the values from LogLevel

Returns:

None

property screenshot_base: bytes

Return the binary screenshot data of the element.

Returns:

bytes - screenshot binary

screenshot_image(screenshot_base: bytes | None = None) Image

Return a PIL.Image.Image object representing the screenshot of the web element. Appium iOS: Take driver screenshot and crop manually element from it

Parameters:

screenshot_base (bytes) – Screenshot binary data (optional). If None is provided then takes a new screenshot

Returns:

PIL.Image.Image

property size: Size

Get the size of the current element, including width and height.

Returns:

Size - An object representing the element’s dimensions.

property text: str

Returns the text of the element.

Returns:

str - element text

type_slowly(text: str, sleep_gap: float = 0.05, silent: bool = False) Element

Types text into the element slowly with a delay between keystrokes.

Parameters:
  • text (str) – The text to be typed.

  • sleep_gap (float) – Delay between keystrokes in seconds.

  • silent (bool) – If True, suppresses logging.

Returns:

Element

type_text(text: str | KeyboardKeys, silent: bool = False) Element

Types text into the element.

Parameters:
  • text (str, KeyboardKeys) – The text to be typed or a keyboard key.

  • silent (bool) – If True, suppresses logging.

Returns:

Element

uncheck() Element

Unchecks the checkbox element.

Returns:

Element

property value: str

Returns the value of the element.

Returns:

str - element value