Implementation:A9T9 RPA getElementByLocator
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, DOM_Resolution |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for resolving Selenium IDE-style locator strings to DOM elements, provided by the Ui.Vision DOM utilities module.
Description
The getElementByLocator and getElementByXPath functions in `src/common/dom_utils.ts` resolve locator strings — the same format the inspector generates during recording — back to live DOM nodes during macro playback. A locator string uses a prefix to indicate the lookup method: `id=`, `name=`, `identifier=`, `link=`, `css=`, `xpath=`, or a bare XPath starting with `/`. There is also an `#elementfrompoint` form for coordinate-based lookup.
`getElementByLocator` parses the prefix, dispatches to the appropriate DOM query, and optionally waits for the element to become visible. `getElementByXPath` runs an XPath query directly. These functions are the bridge between the stored command table (which holds locators) and the live page during replay.
Usage
Import these functions when you need to resolve a stored locator string to a DOM element during macro playback, or to validate that a locator matches a visible element.
Code Reference
Source Location
- Repository: A9T9/RPA
- File: src/common/dom_utils.ts
- Lines: L472-L517 (getElementByXPath), L518-L560 (getElementByLocator)
Signature
export function getElementByXPath(xpath: string): Node | undefined
export function getElementByLocator(
str: string,
shouldWaitForVisible: boolean
): Node | undefined
Import
import { getElementByLocator, getElementByXPath } from '@/common/dom_utils'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| str | string | Yes | Locator string with prefix (id=, name=, identifier=, link=, css=, xpath=) or bare XPath |
| shouldWaitForVisible | boolean | No | If true, wait for element to become visible before returning |
| xpath | string | Yes (getElementByXPath) | XPath expression string |
Outputs
| Name | Type | Description |
|---|---|---|
| return | undefined | The resolved DOM element, or undefined if not found / not visible |
Usage Examples
Resolve a Locator During Playback
import { getElementByLocator } from '@/common/dom_utils'
// Resolve a stored locator to a live element
const el = getElementByLocator('xpath=//button[@id="login"]', true)
if (el) {
(el as HTMLElement).click()
}
Resolve by XPath Directly
import { getElementByXPath } from '@/common/dom_utils'
const node = getElementByXPath('//div[@class="container"]/input[1]')