microsoft/playwright · error · Error
Empty "by" locator. Start with one of by.role(), by.text(),
Error message
Empty "by" locator. Start with one of by.role(), by.text(), by.testId() and friends.
What it means
Error "Empty "by" locator. Start with one of by.role(), by.text(), by.testId() and friends." thrown in microsoft/playwright.
Source
Thrown at packages/isomorphic/by.ts:143
return this._append(name => getByTestIdSelector(name, testId));
}
text(text: string | RegExp, options?: { exact?: boolean }): By {
return this._append(() => getByTextSelector(text, options));
}
title(text: string | RegExp, options?: { exact?: boolean }): By {
return this._append(() => getByTitleSelector(text, options));
}
}
export const by: By = new ByImpl(() => '');
// The test id attribute is only known once the By is bound to a page, hence the deferred build.
export function resolveBy(by: By, testIdAttributeName: string): string {
const selector = (by as ByImpl)._build(testIdAttributeName);
if (!selector)
throw new Error(`Empty "by" locator. Start with one of by.role(), by.text(), by.testId() and friends.`);
return selector;
}
View on GitHub (pinned to c8fc3bf8d3)
When it happens
Trigger: Thrown at packages/isomorphic/by.ts:143 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/657098d242dcce0b.
Report an issue: GitHub.