{"record":{"id":"aaacd73a4e2fd56c","repo":"microsoft/playwright","slug":"frame-locators-are-not-allowed-inside-composite-lo","errorCode":null,"errorMessage":"Frame locators are not allowed inside composite locators, while querying \"${locator}\"","messagePattern":"Frame locators are not allowed inside composite locators, while querying \"(.+?)\"","errorType":"exception","errorClass":"InvalidSelectorError","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/frameSelectors.ts","lineNumber":141,"sourceCode":"      return frame;\n    const body = info.parsed.parts[0].body as string;\n    const match = body.match(/^f(\\d+)e\\d+$/);\n    if (!match)\n      return frame;\n    const frameSeq = +match[1];\n    const jumptToFrame = this.frame._page.frameManager.frames().find(frame => frame.seq === frameSeq);\n    if (!jumptToFrame)\n      throw new InvalidSelectorError(`Invalid frame in aria-ref selector \"${selector}\"`);\n    return jumptToFrame;\n  }\n\n  async resolveFramesForSelector(selector: string, options: types.StrictOptions & { anyFrame?: boolean } = {}, scope?: ElementHandle): Promise<SelectorInFrame[]> {\n    const { anyFrame, chunks } = splitSelectorByFrame(selector);\n    for (const chunk of chunks) {\n      visitAllSelectorParts(chunk, (part, nested) => {\n        if (nested && part.name === 'internal:control' && part.body === 'enter-frame') {\n          const locator = asLocator(this.frame._page.browserContext._browser.sdkLanguage(), selector);\n          throw new InvalidSelectorError(`Frame locators are not allowed inside composite locators, while querying \"${locator}\"`);\n        }\n        if (nested && part.name === 'internal:control' && part.body === 'any-frame') {\n          const locator = asLocator(this.frame._page.browserContext._browser.sdkLanguage(), selector);\n          throw new InvalidSelectorError(`frameLocator() is not allowed inside composite locators, while querying \"${locator}\"`);\n        }\n      });\n    }\n\n    if (!anyFrame && !options.anyFrame) {\n      const result = await this._resolveChainedSelector(this.frame, selector, options, chunks, scope, false /* noStall */);\n      return result ? [result] : [];\n    }\n\n    const result: SelectorInFrame[] = [];\n    const seenFrames = new Set<Frame>();\n    for (const startFrame of await this._anyFrameCandidates(scope)) {\n      const resolved = await this._resolveChainedSelector(startFrame, selector, options, chunks, startFrame === this.frame ? scope : undefined, startFrame !== this.frame /* noStall */);\n      // Different starting frames may resolve into the same frame, e.g. with an aria-ref selector.","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/microsoft/playwright/blob/500c9c822ce7664539a4c8a88810048dfe090c3b/packages/playwright-core/src/server/frameSelectors.ts#L123-L159","documentation":"Frame locators (the internal:control enter-frame part, i.e. frameLocator(...).find(...)) cannot be nested inside a composite (chained) locator. visitAllSelectorParts flags any nested enter-frame part and throws InvalidSelectorError naming the offending locator.","triggerScenarios":"Composing a selector where an iframe-descending locator is used as an inner/non-final part of a larger chain, e.g. combining frameLocator(...).locator(...) as an intermediate segment in a multi-part locator string.","commonSituations":"Building complex selectors by concatenation; converting hand-written query strings that mix iframe traversal with other composite operators; migrations from older selector syntax.","solutions":["Restructure so the frameLocator is the outer chain and only descendant locators live inside it.","Use the frameLocator(...).locator(...).locator(...) API rather than string concatenation.","Split the operation into explicit frame resolution + a within-frame locator query."],"exampleFix":"// before (conceptual): enter-frame nested inside a composite\npage.locator('iframe >> [data-x] >> iframe >> button'); // invalid nesting\n// after: chain frame locators via the API\npage.frameLocator('iframe').locator('[data-x]').locator('button');","handlingStrategy":"validation","validationCode":"// Reject nested frame-locator strings before sending them\nfunction hasNestedFrameLocator(sel: string) {\n  return (sel.match(/>>(?:[^>]*>>){2,}/) || []).length > 0;\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Use the Locator API (frameLocator/locator) instead of raw selector strings.","Never concatenate iframe-traversal tokens into one composite string."],"tags":["selector","frame-locator","validation"],"backgroundTag":null,"analyzedSha":"500c9c822ce7664539a4c8a88810048dfe090c3b","analyzedAt":"2026-09-01T05:48:36.844Z","contentChangedAt":"2026-09-01T05:48:36.844Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}