{"record":{"id":"4dca02ba57109097","repo":"grafana/k6","slug":"selecting-text-w","errorCode":null,"errorMessage":"selecting text: %w","messagePattern":"selecting text: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1446,"sourceCode":"\tif err := convert(selectedOptions, &returnVal); err != nil {\n\t\treturn nil, fmt.Errorf(\"unpacking selected options: %w\", err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn returnVal, nil\n}\n\n// SelectText selects the text of the element.\nfunc (h *ElementHandle) SelectText(opts *ElementHandleBaseOptions) error {\n\tselectText := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn nil, handle.selectText(apiCtx)\n\t}\n\tselectTextAction := h.newAction(\n\t\t[]string{}, selectText, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tif _, err := call(h.ctx, selectTextAction, opts.Timeout); err != nil {\n\t\treturn fmt.Errorf(\"selecting text: %w\", err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn nil\n}\n\n// SetInputFiles sets the given files into the input file element.\nfunc (h *ElementHandle) SetInputFiles(files *Files, opts *ElementHandleSetInputFilesOptions) error {\n\tsetInputFiles := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn nil, handle.setInputFiles(apiCtx, files)\n\t}\n\tsetInputFilesAction := h.newAction([]string{}, setInputFiles, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout)\n\tif _, err := call(h.ctx, setInputFilesAction, opts.Timeout); err != nil {\n\t\treturn fmt.Errorf(\"setting input files: %w\", err)\n\t}\n\n\treturn nil","sourceCodeStart":1428,"sourceCodeEnd":1464,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1428-L1464","documentation":"Wrapped failure from ElementHandle.SelectText (k6 browser API elementHandle.selectText()). The inner error comes from running the injected-script selectText in the page plus the action wrapper's actionability retry loop: the element is not a text-editable node, is hidden or detached, or the action exceeded its timeout. The wrapper adds the 'selecting text:' prefix so the failing step is identifiable in the script log.","triggerScenarios":"Calling handle.selectText() on an element that is not an <input>, <textarea> or [contenteditable] node (injected script returns error:notfillableelement); calling it on a display:none or detached element; the withRetry action loop hitting the timeout (default 30s, or opts.Timeout) while the element never becomes actionable.","commonSituations":"SPA frameworks (React/Vue) re-rendering and invalidating the handle between query and selectText; textareas hidden behind accordions/tabs opened later; slow CI machines where the default timeout is too short.","solutions":["Re-acquire the element with page.waitForSelector(sel, { state: 'visible' }) immediately before selectText","Increase the timeout: el.selectText({ timeout: '60s' })","Verify the target is an input/textarea/contenteditable element, not a div or span","If the element is intentionally not actionable yet, wait for it: el.waitForElementState('visible')"],"exampleFix":"// before\nconst el = page.$('#notes');\nel.selectText(); // fails: element hidden or not editable\n\n// after\nconst el = page.waitForSelector('#notes', { state: 'visible' });\nif (el && el.isVisible()) {\n  el.selectText({ timeout: '30s' });\n}","handlingStrategy":"try-catch","validationCode":"const el = page.waitForSelector('#notes', { state: 'visible' });\nif (!el || !el.isVisible()) {\n  throw new Error('#notes is not visible; cannot select text');\n}","typeGuard":null,"tryCatchPattern":"try {\n  el.selectText({ timeout: '30s' });\n} catch (e) {\n  if (String(e).includes('selecting text')) {\n    // re-query once: handles can go stale after re-renders\n    page.waitForSelector('#notes', { state: 'visible' }).selectText();\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always acquire elements with waitForSelector(..., { state: 'visible' }) right before selectText","Pass an explicit timeout instead of relying on the 30s default","Only call selectText on input/textarea/contenteditable targets"],"tags":["browser","dom","actionability","timeout","element-handle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}