{"record":{"id":"42e4abdc533305f8","repo":"grafana/k6","slug":"error-while-parsing-selector-selector-canno-42e4ab","errorCode":null,"errorMessage":"Error while parsing selector `${selector}` - cannot use ${operator} in attribute with non-string matching value - ${value}","messagePattern":"Error while parsing selector `(.+?)` - cannot use (.+?) in attribute with non-string matching value - (.+?)","errorType":"exception","errorClass":"InvalidSelectorError","httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/js/injected_script.js","lineNumber":1125,"sourceCode":"        value += eat1();\n      if (value === \"true\") {\n        value = true;\n      } else if (value === \"false\") {\n        value = false;\n      } else {\n        if (!allowUnquotedStrings) {\n          value = +value;\n          if (Number.isNaN(value))\n            syntaxError(\"parsing attribute value\");\n        }\n      }\n    }\n    skipSpaces();\n    if (next() !== \"]\")\n      syntaxError(\"parsing attribute value\");\n    eat1();\n    if (operator !== \"=\" && typeof value !== \"string\")\n      throw new InvalidSelectorError(`Error while parsing selector \\`${selector}\\` - cannot use ${operator} in attribute with non-string matching value - ${value}`);\n    return { name: jsonPath.join(\".\"), jsonPath, op: operator, value, caseSensitive };\n  }\n  const result = {\n    name: \"\",\n    attributes: []\n  };\n  result.name = readIdentifier();\n  skipSpaces();\n  while (next() === \"[\") {\n    result.attributes.push(readAttribute());\n    skipSpaces();\n  }\n  if (!EOL)\n    syntaxError(void 0);\n  if (!result.name && !result.attributes.length)\n    throw new InvalidSelectorError(`Error while parsing selector \\`${selector}\\` - selector cannot be empty`);\n  return result;\n}","sourceCodeStart":1107,"sourceCodeEnd":1143,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/js/injected_script.js#L1107-L1143","documentation":"Frame.GetAttribute() (frame.go:1002) wraps the internal getAttribute action error with 'getting attribute %q of %q'. The action waits for an element matching the selector to attach within Timeout, then evaluates element.getAttribute(name) in the page. Failures wrapped here are selector/timeout failures (element not found, strict mode violation), detached frames, or evaluation errors from the page.","triggerScenarios":"Selector matches nothing before opts.Timeout expires; Strict:true with multiple matches; frame navigated/detached during resolution; the injected evaluation throws (e.g., page scripts overriding Element.prototype.getAttribute with a throwing getter).","commonSituations":"Reading href/value attributes of elements rendered after async data loads; attribute names with typos or wrong casing for SVG/XML documents; elements inside iframes queried on the wrong frame object.","solutions":["Wait for the element first: await page.waitForSelector(sel, { timeout: 10000 }) before GetAttribute.","Query the correct frame: get the iframe's frame from page.frames() and call getAttribute on it.","Double-check the attribute name and casing (SVG uses xlink:href style names).","Raise the timeout explicitly if the element appears late: page.getAttribute(sel, name, { timeout: 60000 })."],"exampleFix":"// before\nconst href = await page.getAttribute('a.details', 'href');\n\n// after\nconst link = page.locator('a.details');\nawait link.waitFor({ state: 'attached', timeout: 10000 });\nconst href = await link.getAttribute('href');","handlingStrategy":"try-catch","validationCode":"await page.waitForSelector('a.details', { state: 'attached', timeout: 5000 }); // element present before attribute read","typeGuard":null,"tryCatchPattern":"try {\n  return await page.getAttribute(sel, name, { timeout: 10000 });\n} catch (e) {\n  const msg = String(e);\n  if (msg.includes('timed out')) return null; // element absent; treat as missing attribute\n  throw e;\n}","preventionTips":["Wait for the element (attached) before reading attributes.","Confirm attribute spelling/casing, especially for SVG namespaced attributes.","Run attribute reads on the frame that owns the element."],"tags":["k6","browser","frame","getattribute","selector","timeout"],"backgroundTag":"element-not-found-timeout","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"}