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, *, located=None) ¶
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.
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, *, located=None) ¶
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.
enter_text(element, text, aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100', event_name=None, *, located=None) ¶
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.
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., '
: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) ¶
Get the text from a specified element.
:param element: The target element (Image template, OCR template, or XPath). :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, *, located=None) ¶
Press a specified checkbox element.
: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.
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, *, located=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, *, located=None) ¶
Press a specified radio button.
: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.
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, *, located=None) ¶
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.
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, event_name=None) ¶
Select a specified dropdown option.
:param element: The dropdown element (Image template, OCR template, or XPath). :param option: The option to be selected. :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_from_element(element, direction, swipe_length, aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100', event_name=None, *, located=None) ¶
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.
swipe_seekbar_to_right_android(element, event_name=None) ¶
Swipe a seekbar to the right.
: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.