Get an element with the given user-defined key. Parameters ---------- locator : Locator The locator to search for the element. key : str The user-defined key of the element Returns ------- Locator The element.
(locator: Locator | Page, key: str)
| 1121 | |
| 1122 | |
| 1123 | def get_element_by_key(locator: Locator | Page, key: str) -> Locator: |
| 1124 | """Get an element with the given user-defined key. |
| 1125 | |
| 1126 | Parameters |
| 1127 | ---------- |
| 1128 | locator : Locator |
| 1129 | The locator to search for the element. |
| 1130 | |
| 1131 | key : str |
| 1132 | The user-defined key of the element |
| 1133 | |
| 1134 | Returns |
| 1135 | ------- |
| 1136 | Locator |
| 1137 | The element. |
| 1138 | |
| 1139 | """ |
| 1140 | class_name = re.sub(r"[^a-zA-Z0-9_-]", "-", key.strip()) |
| 1141 | class_name = f"st-key-{class_name}" |
| 1142 | return locator.locator(f".{class_name}") |
| 1143 | |
| 1144 | |
| 1145 | def expand_sidebar(app: Page) -> Locator: |
searching dependent graphs…