Appearance
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
| Parameter | Type | Description |
|---|---|---|
ctx | Context | The context for automation. |
selectors | [string, ...string[]] | An array of CSS selectors to race. |
options? | WaitForSelectorOptions | Optional 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'