Skip to content

Function: raceSelectors()

ts
function raceSelectors(
   ctx: Context, 
   selectors: [string, ...string[]], 
   options?: WaitForSelectorOptions): Promise<{
  result: ElementHandle<Element> | null;
  winner: string;
}>;

Defined in: src/utils/raceSelectors.ts:20

Race multiple selectors and return the first match.

Parameters

ParameterTypeDescription
ctxContextThe context for automation.
selectors[string, ...string[]]An array of CSS selectors to race.
options?WaitForSelectorOptionsOptional configuration for waitForSelector.

Returns

Promise<{ result: ElementHandle<Element> | null; winner: string; }>

An object with result (the matched element) and winner (the winning selector).

Throws

If no selectors are provided or any selector is empty.

Example

ts
const { result, winner } = await raceSelectors(ctx, ['#checkout', '#cart', '#login']);
console.log(winner); // '#checkout'

Matterway Assistant SDK Documentation