Skip to content

Function: getProperty()

ts
function getProperty(
   ctx: Context, 
   selector: string, 
   propertyName: string, 
options?: WaitForSelectorOptions): Promise<string | null>;

Defined in: src/dom/index.ts:67

Return the value of an element attribute.

Parameters

ParameterTypeDescription
ctxContextContext object.
selectorstringCSS or XPath selector for the target element.
propertyNamestringThe attribute name to read.
options?WaitForSelectorOptionsWait options for the selector lookup.

Returns

Promise<string | null>

The attribute value as a string, or null if not found.

Example

ts
// Read the data-product-id from a catalog item
const productId = await getProperty(ctx, '.product-card', 'data-product-id');

Matterway Assistant SDK Documentation