Appearance
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
| Parameter | Type | Description |
|---|---|---|
ctx | Context | Context object. |
selector | string | CSS or XPath selector for the target element. |
propertyName | string | The attribute name to read. |
options? | WaitForSelectorOptions | Wait 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');