Skip to main content

sdk.watcher.watchxpath

Home > @matterway/sdk > Watcher > watchXpath

Watcher.watchXpath() function

Watches an element by XPath selector, and executes code when it appears or disappears.

Signature:

export declare function watchXpath(ctx: Context, selector: string, options?: Partial<WatchSelectorOptions>): import("./watcher").Watcher<ElementHandle<Node>>;

Parameters

ParameterTypeDescription
ctxContextContext object.
selectorstringXpath selector to watch.
optionsPartial<WatchSelectorOptions>(Optional) Enter, leave callbacks and ensureVisible flag.

Returns:

import("./watcher").Watcher<ElementHandle<Node>>

Example

const watcher = watchXpath(ctx, '//div', {
async enter: (el: ElementHandle) => {
// Do something with the matched el when it appears
},
async leave: (el: ElementHandle) => {
// Do something with the matched el when it disappears
},
});
// ...
watcher.stop()