Skip to content

Action Keywords

The ActionKeyword class provides methods for interacting with elements, including pressing, swiping, typing, and other user actions.

optics_framework.api.action_keyword.ActionKeyword

High-Level API for Action Keywords

This class provides functionality for managing action keywords related to applications, including pressing elements, scrolling, swiping, and text input.

clear_element_text(element, aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100', event_name=None, index='0')

Clear text from a specified element.

:param element: The target element (Image template, OCR template, or XPath). :param aoi_x: X percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_y: Y percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_width: Width percentage of Area of Interest (0-100). Default: 100. :param aoi_height: Height percentage of Area of Interest (0-100). Default: 100. :param event_name: The event triggering the action. :param index: Index of the element if multiple matches are found.

detect_and_press(element, timeout='30', event_name=None)

Detect and press a specified element.

:param element: The element to be detected and pressed (Image template, OCR template, or XPath). :param timeout: Timeout for the detection operation. :param event_name: The event triggering the press.

enter_number(element, number, aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100', event_name=None, index='0')

Enter a specified number into an element.

:param element: The target element (Image template, OCR template, or XPath). :param number: The number to be entered. :param aoi_x: X percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_y: Y percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_width: Width percentage of Area of Interest (0-100). Default: 100. :param aoi_height: Height percentage of Area of Interest (0-100). Default: 100. :param event_name: The event triggering the input. :param index: Index of the element if multiple matches are found.

enter_text(element, text, aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100', event_name=None, index='0')

Enter text into a specified element.

:param element: The target element (Image template, OCR template, or XPath). :param text: The text to be entered. :param aoi_x: X percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_y: Y percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_width: Width percentage of Area of Interest (0-100). Default: 100. :param aoi_height: Height percentage of Area of Interest (0-100). Default: 100. :param event_name: The event triggering the input. :param index: Index of the element if multiple matches are found.

enter_text_direct(text, event_name=None)

Enter text using the keyboard.

:param text: The text to be entered. :param event_name: The event triggering the input.

enter_text_using_keyboard(text_input, event_name=None)

Enter text or press a special key using the keyboard.

If the input is a string that includes angle brackets (e.g., ''), the text between the brackets will be interpreted as a special key name and mapped accordingly.

:param input: The text or special key identifier to send. :param event_name: Optional event label for logging.

execute_script(script_or_json, event_name=None)

Execute JavaScript/script in the current context.

:param script_or_json: The JavaScript code/script command, or a JSON string containing {"script": "...", "args": {...}} or {"script": "..."}. Examples: - "mobile:pressKey" (plain script) - '{"script": "mobile:pressKey", "args": {"keycode": 3}}' (JSON with args) - '{"script": "mobile:clear"}' (JSON without args) :type script_or_json: str :param event_name: The event triggering the script execution, if any. :type event_name: Optional[str] :return: The result of the script execution. :rtype: Any

get_text(element, index='0', aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100')

Get the text from a specified element.

:param element: The target element (Image template, OCR template, or XPath). :param index: Index of the element if multiple matches are found. :param aoi_x: X percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_y: Y percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_width: Width percentage of Area of Interest (0-100). Default: 100. :param aoi_height: Height percentage of Area of Interest (0-100). Default: 100. :return: The text from the element or None if not supported.

press_by_coordinates(coor_x, coor_y, repeat='1', event_name=None)

Press an element by absolute coordinates.

:param coor_x: X coordinate of the press. :param coor_y: Y coordinate of the press. :param repeat: Number of times to repeat the press. :param event_name: The event triggering the press.

press_by_percentage(percent_x, percent_y, repeat='1', event_name=None)

Press an element by percentage coordinates.

:param percent_x: X percentage of the press (as string, will be converted to float). :param percent_y: Y percentage of the press (as string, will be converted to float). :param repeat: Number of times to repeat the press. :param event_name: The event triggering the press.

press_checkbox(element, aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100', event_name=None, index='0')

Press a specified checkbox element.

.. deprecated:: Deprecated alias of :meth:press_element — use Press Element directly.

:param element: The checkbox element (Image template, OCR template, or XPath). :param aoi_x: X percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_y: Y percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_width: Width percentage of Area of Interest (0-100). Default: 100. :param aoi_height: Height percentage of Area of Interest (0-100). Default: 100. :param event_name: The event triggering the press. :param index: Index of the element if multiple matches are found.

press_element(element, repeat='1', offset_x='0', offset_y='0', index='0', aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100', event_name=None)

Press a specified element.

:param element: The element to be pressed (text, xpath or image). :param repeat: Number of times to repeat the press. :param offset_x: X offset of the press. :param offset_y: Y offset of the press. :param index: Index of the element if multiple matches are found. :param event_name: The event triggering the press. :param aoi_x: X percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_y: Y percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_width: Width percentage of Area of Interest (0-100). Default: 100. :param aoi_height: Height percentage of Area of Interest (0-100). Default: 100.

press_keycode(keycode, event_name=None)

Press a specified keycode.

:param keycode: The keycode to be pressed. :param event_name: The event triggering the press.

press_radio_button(element, aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100', event_name=None, index='0')

Press a specified radio button.

.. deprecated:: Deprecated alias of :meth:press_element — use Press Element directly.

:param element: The radio button element (Image template, OCR template, or XPath). :param aoi_x: X percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_y: Y percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_width: Width percentage of Area of Interest (0-100). Default: 100. :param aoi_height: Height percentage of Area of Interest (0-100). Default: 100. :param event_name: The event triggering the press. :param index: Index of the element if multiple matches are found.

scroll(direction, event_name=None)

Perform a scroll action in a specified direction.

:param direction: The scroll direction (up, down, left, right). :param event_name: The event triggering the scroll.

scroll_from_element(element, direction, scroll_length, aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100', event_name=None, index='0')

Perform a scroll action starting from a specified element.

:param element: The element to scroll from (Image template, OCR template, or XPath). :param direction: The scroll direction (up, down, left, right). :param scroll_length: The length of the scroll. :param aoi_x: X percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_y: Y percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_width: Width percentage of Area of Interest (0-100). Default: 100. :param aoi_height: Height percentage of Area of Interest (0-100). Default: 100. :param event_name: The event triggering the scroll. :param index: Index of the element if multiple matches are found.

scroll_until_element_appears(element, direction, timeout, event_name=None)

Scroll in a specified direction until an element appears.

:param element: The target element (Image template, OCR template, or XPath). :param direction: The scroll direction (up, down, left, right). :param timeout: Timeout for the scroll operation. :param event_name: The event triggering the scroll.

select_dropdown_option(element, option, timeout='30', event_name=None)

Open a dropdown and select one of its options, scrolling through the list if needed.

Opens the dropdown by pressing element. If option isn't visible right away, diffs the interactive elements captured before and after opening to find the dropdown's list container, then scrolls within that container (never past the page behind it) until option appears or the list stops changing. Raises OpticsError (E0201``) ifoptionis never found withintimeout` seconds.

Falls back to a single-screen check (no scrolling) when page source, or a list-like container, isn't available.

Assumption: opened dropdown list is opened in such a way that the topmost option is visible on the screen

:param element: The dropdown element (Image template, OCR template, or XPath). :param option: The option to select (visible label, OCR/Image template, or XPath). :param timeout: Seconds to keep scrolling through the dropdown list before failing. :param event_name: The event triggering the selection.

sleep(duration)

Sleep for a specified duration.

:param duration: The duration of the sleep in seconds.

swipe(coor_x, coor_y, direction='right', swipe_length='50', event_name=None)

Perform a swipe action in a specified direction.

:param coor_x: X coordinate of the swipe. :param coor_y: Y coordinate of the swipe. :param direction: The swipe direction (up, down, left, right). :param swipe_length: The length of the swipe. :param event_name: The event triggering the swipe.

swipe_by_percentage(percent_x, percent_y, direction='right', swipe_length='50', event_name=None)

Perform a swipe action in a specified direction by percentage.

:param percent_x: X percentage of the swipe. :param percent_y: Y percentage of the swipe. :param direction: The swipe direction (up, down, left, right). :param swipe_length: The length of the swipe. :param event_name: The event triggering the swipe.

swipe_from_element(element, direction, swipe_length, aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100', event_name=None, index='0')

Perform a swipe action starting from a specified element.

:param element: The element to swipe from (Image template, OCR template, or XPath). :param direction: The swipe direction (up, down, left, right). :param swipe_length: The length of the swipe. :param aoi_x: X percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_y: Y percentage of Area of Interest top-left corner (0-100). Default: 0. :param aoi_width: Width percentage of Area of Interest (0-100). Default: 100. :param aoi_height: Height percentage of Area of Interest (0-100). Default: 100. :param event_name: The event triggering the swipe. :param index: Index of the element if multiple matches are found.

swipe_seekbar_to_right_android(element, event_name=None)

Swipe a seekbar to the right.

.. deprecated:: Deprecated; prefer :meth:swipe_from_element / :meth:swipe.

:param element: The seekbar element (Image template, OCR template, or XPath).

swipe_until_element_appears(element, direction, timeout, event_name=None)

Swipe in a specified direction until an element appears.

:param element: The target element (Image template, OCR template, or XPath). :param direction: The swipe direction (up, down, left, right). :param timeout: Timeout until element search is performed. :param event_name: The event triggering the swipe.