*** Settings ***
Library ExtendedWindows.py
*** Tasks ***
Minimal task
Control Window name:Calculator
FOR ${idx} IN RANGE 2 11
${element}= Get Element With Path 2|3|2|8|2|2|5|${idx}
IF ${idx}==2 Log To Console ${{dir($element.item)}}
Click ${element}
END
Log Done.
Custom Python library implementation
from RPA.Windows import Windows
from RPA.core.windows.locators import WindowsElement
from robot.api.deco import keyword
import logging
class ExtendedWindows(Windows):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@keyword
def get_element_with_path(self, element_path: str, log_elements: bool = False) -> WindowsElement:
root = self.window_element.item
element_index_path = [item.strip() for item in element_path.split("|")]
child_elements = []
target = None
for idx in element_index_path:
child_idx = int(idx) - 1
if log_elements:
logging.warning(root)
child_elements = root.GetChildren()
if child_idx < len(child_elements):
root = child_elements[child_idx]
root.robocorp_click_offset = None
target = WindowsElement(root, element_path)
return target
Robot Framework usage example
Custom Python library implementation
An example how element path indexes are calculate