(Created on )

Puppeteer: Unknown locator for race candidate

Locator.race receives a candidate that is not a Puppeteer Locator.


Locator.race receives a candidate that is not a Puppeteer Locator.

Error message

Unknown locator for race candidate

How this error happens

Locator.race takes Locator objects. Selector strings are not converted into locators automatically.

The fix uses an open page named page and the same imported Locator.

import {
    Locator,
} from "puppeteer";

Locator.race([
    "#success",
    "#failure",
]);

How to fix

Create a locator for each candidate first.

const result = Locator.race([
    page.locator("#success"),
    page.locator("#failure"),
]);

const element = await result.waitHandle();

Things to keep in mind

The corrected example assumes the application eventually renders either result. Racing locators does not create the matching element.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →