{"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":1450,"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":1432,"sourceCodeEnd":1468,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L1432-L1468","documentation":"Thrown by the k6 browser module's ElementHandle.selectText(). It wraps failure of the selectText action: the timeout expiring before the element is actionable, the element being detached, or the injected script returning a DOM error string (via errorFromDOMError) such as 'node is not an element' or a not-editable/not-selectable indicator.","triggerScenarios":"Calling el.selectText() on a detached or hidden element; on an element whose text cannot be selected (e.g., an <input> where text selection semantics differ); while the page rerenders and invalidates the handle; with the default timeout too short.","commonSituations":"Attempting selectText on content that a framework re-renders mid-selection; hidden elements behind tabs/accordions not yet expanded; CI slowness causing the actionability retry window to expire.","solutions":["Ensure the element is visible and stable first: await el.waitForElementState('visible', { timeout: '30s' }) before selectText.","Re-query the handle immediately before the call: el = await page.waitForSelector(selector).","Increase the timeout: el.selectText({ timeout: '60s' }).","Pass { force: true } to bypass actionability checks when you know the node is attached."],"exampleFix":"// before\nconst el = await page.$('#snippet');\nawait el.selectText(); // fails while accordion section collapsed\n\n// after\nawait page.click('#section-header'); // expand first\nconst el = await page.waitForSelector('#snippet', { state: 'visible' });\nawait el.selectText({ timeout: '30s' });","handlingStrategy":"try-catch","validationCode":"const visible = await el.isVisible().catch(() => false);\nif (visible) { await el.selectText({ timeout: '30s' }); }","typeGuard":null,"tryCatchPattern":"try {\n  await el.selectText({ timeout: '30s' });\n} catch (e) {\n  if (String(e).includes('timed out')) {\n    el = await page.waitForSelector(sel, { state: 'visible' });\n    await el.selectText({ timeout: '30s' });\n  } else { throw e; }\n}","preventionTips":["Expand collapsed containers before selecting text in them.","Re-query the handle immediately before selectText on dynamic pages."],"tags":["k6","browser","element-handle","actionability","timeout"],"backgroundTag":"browser-action-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"}