{"record":{"id":"5094ac7d0918bd1a","repo":"grafana/k6","slug":"getting-element-s-inner-text-w","errorCode":null,"errorMessage":"getting element's inner text: %w","messagePattern":"getting element's inner text: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1021,"sourceCode":"\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type %T (expecting string)\", v)\n\t}\n\n\treturn s, nil\n}\n\n// InnerText returns the inner text of the element.\nfunc (h *ElementHandle) InnerText() (string, error) {\n\tinnerText := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.innerText(apiCtx)\n\t}\n\topts := NewElementHandleBaseOptions(h.DefaultTimeout())\n\tinnerTextAction := h.newAction(\n\t\t[]string{}, innerText, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout.Abs(),\n\t)\n\tv, err := call(h.ctx, innerTextAction, opts.Timeout)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"getting element's inner text: %w\", err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\ts, ok := v.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type %T (expecting string)\", v)\n\t}\n\n\treturn s, nil\n}\n\n// InputValue returns the value of the input element.\nfunc (h *ElementHandle) InputValue(opts *ElementHandleBaseOptions) (string, error) {\n\tinputValue := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.inputValue(apiCtx)\n\t}\n\tinputValueAction := h.newAction([]string{}, inputValue, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout)","sourceCodeStart":1003,"sourceCodeEnd":1039,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1003-L1039","documentation":"Returned by ElementHandle.innerText() when the underlying evaluation fails. The method evaluates element.innerText via CDP with returnByValue (note it passes opts.Timeout.Abs() to the action); this error wraps CDP failures, stale handles, destroyed execution contexts, or an expired timeout.","triggerScenarios":"Calling innerText() on a detached handle or one captured before navigation; the page navigating while the evaluation runs; the action timeout expiring; the browser/page closing mid-call.","commonSituations":"Extracting visible text from re-rendering SPA lists; reading text right after a click that navigates; slow CI browsers hitting the default timeout.","solutions":["Wait for the element: page.waitForSelector(sel, { state: 'attached' })","Re-query the handle right before innerText()","Await page.waitForLoadState() after navigations before reading text","Increase the action/browser timeout if the wrapped cause is a timeout"],"exampleFix":"// before\nconst text = await (await page.$('#msg')).innerText();\n// after\nawait page.waitForSelector('#msg', { state: 'attached' });\nconst el = await page.$('#msg');\nconst text = await el.innerText();","handlingStrategy":"try-catch","validationCode":"await page.waitForSelector('#msg', { state: 'attached' });\nconst el = await page.$('#msg');\nif (el) {\n  const text = await el.innerText();\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await handle.innerText();\n} catch (e) {\n  if (String(e).includes(\"getting element's inner text\")) {\n    await page.waitForLoadState();\n    return (await page.$(sel)).innerText();\n  }\n  throw e;\n}","preventionTips":["waitForSelector(attached) before text reads","Re-query handles after dynamic re-renders","Set explicit timeouts for slow pages"],"tags":["browser","element-handle","inner-text","detached-handle","timeout"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}