Implementation:A9T9 RPA Inspector getLocator
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, DOM_Recording |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for generating Selenium IDE-style element locators from DOM nodes during macro recording, provided by the Ui.Vision inspector module.
Description
The inspector module (default export of `src/common/inspector.js`) provides the locator-generation layer used when a user records a macro by interacting with a web page. When the content script intercepts a click, input, or change event, it calls `inspector.getLocator($el)` to produce a stable locator string (XPath, CSS selector, link text, or id/name) that can be stored in the command table and replayed later.
The module also exposes helpers for XPath generation (`xpath`), CSS selector generation (`selector`), frame locator generation (`getFrameLocator`), and visibility/DOM checks (`isVisible`, `inDom`). Recording itself is driven by event listeners in the content script (`src/ext/content_script/index.js`), which combine DOM event interception with inspector locator generation — there is no single `inspector.attach` function; the content script wires the listeners and calls `getLocator` per interaction.
Usage
Import the inspector when you need to convert a live DOM element into a replayable locator string during recording, or to generate XPath/CSS selectors for arbitrary DOM nodes.
Code Reference
Source Location
- Repository: A9T9/RPA
- File: src/common/inspector.js
- Lines: L33-L360 (locator/XPath/selector generation), L692-L707 (default export object)
Signature
// Default export object
export default {
offset(el), // Get element offset/position
setStyle(el, style), // Apply styles (e.g. recording highlight)
selector(el), // Generate CSS selector for element
xpath(el), // Generate XPath for element
atXPath(xpath), // Resolve an XPath to a node
domText(el), // Get text content of element
getLocator($el), // Generate best locator string for element
getFrameLocator(win), // Generate frame locator for iframe window
maskFactory(), // Create overlay mask factory
showMaskOver(el), // Show visual mask over element
inDom(el), // Check if element is in the DOM
isVisible(el), // Check if element is visible
parentWithTag(el, tag), // Find parent with given tag
parentWithClass(el, cls) // Find parent with given class
}
Import
import inspector from '@/common/inspector'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| $el | Node | Yes | The target DOM element to generate a locator for |
Outputs
| Name | Type | Description |
|---|---|---|
| locator | string | Selenium IDE-style locator string (e.g. `xpath=//div[@id="x"]`, `css=.btn`, `id=submit`) |
Usage Examples
Generate a Locator for a Clicked Element
import inspector from '@/common/inspector'
// Inside a content-script click handler during recording
document.addEventListener('click', (e) => {
const locator = inspector.getLocator(e.target)
// locator e.g. "xpath=//button[@id='login']"
console.log('Recorded locator:', locator)
}, true)
Generate XPath and CSS Selectors
import inspector from '@/common/inspector'
const el = document.querySelector('#my-button')
const xp = inspector.xpath(el) // e.g. "//div[@id='container']/button"
const cs = inspector.selector(el) // e.g. "#my-button"