{"record":{"id":"1a9c9786a36ad5e9","repo":"grafana/k6","slug":"error-while-parsing-selector-selector-canno","errorCode":null,"errorMessage":"Error while parsing selector `${selector}` - cannot use ${operator} in attribute with regular expression","messagePattern":"Error while parsing selector `(.+?)` - cannot use (.+?) in attribute with regular expression","errorType":"exception","errorClass":"InvalidSelectorError","httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/js/injected_script.js","lineNumber":1092,"sourceCode":"    const jsonPath = [];\n    jsonPath.push(readAttributeToken());\n    skipSpaces();\n    while (next() === \".\") {\n      eat1();\n      jsonPath.push(readAttributeToken());\n      skipSpaces();\n    }\n    if (next() === \"]\") {\n      eat1();\n      return { name: jsonPath.join(\".\"), jsonPath, op: \"<truthy>\", value: null, caseSensitive: false };\n    }\n    const operator = readOperator();\n    let value = void 0;\n    let caseSensitive = true;\n    skipSpaces();\n    if (next() === \"/\") {\n      if (operator !== \"=\")\n        throw new InvalidSelectorError(`Error while parsing selector \\`${selector}\\` - cannot use ${operator} in attribute with regular expression`);\n      value = readRegularExpression();\n    } else if (next() === `'` || next() === `\"`) {\n      value = readQuotedString(next()).slice(1, -1);\n      skipSpaces();\n      if (next() === \"i\" || next() === \"I\") {\n        caseSensitive = false;\n        eat1();\n      } else if (next() === \"s\" || next() === \"S\") {\n        caseSensitive = true;\n        eat1();\n      }\n    } else {\n      value = \"\";\n      while (!EOL && (isCSSNameChar(next()) || next() === \"+\" || next() === \".\"))\n        value += eat1();\n      if (value === \"true\") {\n        value = true;\n      } else if (value === \"false\") {","sourceCodeStart":1074,"sourceCodeEnd":1110,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/js/injected_script.js#L1074-L1110","documentation":"Frame.FrameElement() (frame.go:990) returns the ElementHandle for a frame (the <iframe> or <frame> element in its parent document) via page.getFrameElement. The wrapper 'getting frame element' fires when that lookup fails: typically because the frame is already detached, its CDP session is gone, or resolving the frame owner through the DevTools protocol errored.","triggerScenarios":"The iframe was removed from the DOM or navigated away before the call; the frame's page was closed; the parent document changed so the frame's owner node no longer resolves; CDP session issues after browser/context crash.","commonSituations":"Scripts holding a stale Frame reference from page.frames() after the SPA replaced an iframe; ad or embed iframes that unload quickly; calling FrameElement during teardown after context.close().","solutions":["Re-acquire the frame right before use: const f = page.frames().find(fr => fr.name() === 'myframe'); then call f.frameElement().","Do the call before triggering any action that can navigate or remove the iframe.","Check page.frames() length/content to confirm the frame still exists.","If the error appears after closing pages, restructure the script to finish iframe work before context/page close."],"exampleFix":"// before\nconst f = page.frames()[2]; // captured earlier, iframe may be gone\nconst el = await f.frameElement();\n\n// after\nconst f = page.frames().find(fr => fr.url().includes('/widget'));\nif (!f) throw new Error('widget frame not attached');\nconst el = await f.frameElement();","handlingStrategy":"validation","validationCode":"const f = page.frames().find(fr => fr.url().includes('/widget'));\nif (!f) throw new Error('widget frame is not attached; cannot get frame element');\nconst el = await f.frameElement();","typeGuard":null,"tryCatchPattern":"try {\n  return await frame.frameElement();\n} catch (e) {\n  if (String(e).includes('getting frame element')) return null; // frame gone; caller re-discovers\n  throw e;\n}","preventionTips":["Look frames up from page.frames() immediately before use instead of caching references.","Finish iframe interactions before closing or navigating the parent page.","Assert on the iframe's presence (by name/url) as an explicit step in the script."],"tags":["k6","browser","frame","iframe","cdp"],"backgroundTag":"frame-detached","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}