microsoft/playwright · error · Error
Selecting the nth frame is not allowed on the root frame loc
Error message
Selecting the nth frame is not allowed on the root frame locator.
What it means
Error "Selecting the nth frame is not allowed on the root frame locator." thrown in microsoft/playwright.
Source
Thrown at packages/playwright-core/src/client/locator.ts:511
}
getByRole(role: string, options: ByRoleOptions = {}): Locator {
return this.locator(getByRoleSelector(role, options));
}
owner() {
return new Locator(this._frame, this._frameSelector);
}
frameLocator(selector: string): FrameLocator {
return new FrameLocator(this._frame, this._childSelector(selector));
}
private _nthSelector(nth: string): string {
if (selectorPiercesFrames(this._frameSelector))
throw new Error(`Selecting the nth frame is not allowed while piercing frames.`);
if (this._frameSelector === kNoPierceFramesSelector)
throw new Error(`Selecting the nth frame is not allowed on the root frame locator.`);
return this._frameSelector + ` >> nth=${nth}`;
}
first(): FrameLocator {
return new FrameLocator(this._frame, this._nthSelector('0'));
}
last(): FrameLocator {
return new FrameLocator(this._frame, this._nthSelector('-1'));
}
nth(index: number): FrameLocator {
return new FrameLocator(this._frame, this._nthSelector(String(index)));
}
}
let _testIdAttributeName: string = 'data-testid';
View on GitHub (pinned to c8fc3bf8d3)
When it happens
Trigger: Thrown at packages/playwright-core/src/client/locator.ts:511 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/e4bd1446e0c62274.
Report an issue: GitHub.