{"record":{"id":"207ac77a58d0f1da","repo":"grafana/k6","slug":"filling-element-w","errorCode":null,"errorMessage":"filling element: %w","messagePattern":"filling element: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":916,"sourceCode":"\t\treturn fmt.Errorf(\"dispatching element event %q: %w\", typ, err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn nil\n}\n\n// Fill types the given value into the element.\nfunc (h *ElementHandle) Fill(value string, opts *ElementHandleBaseOptions) error {\n\tfill := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn nil, handle.fill(apiCtx, value)\n\t}\n\tfillAction := h.newAction(\n\t\t[]string{\"visible\", \"enabled\", \"editable\"},\n\t\tfill, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tif _, err := call(h.ctx, fillAction, opts.Timeout); err != nil {\n\t\treturn fmt.Errorf(\"filling element: %w\", err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn nil\n}\n\n// Focus scrolls element into view and focuses the element.\nfunc (h *ElementHandle) Focus() error {\n\tfocus := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn nil, handle.focus(apiCtx, false)\n\t}\n\topts := NewElementHandleBaseOptions(h.DefaultTimeout())\n\tfocusAction := h.newAction(\n\t\t[]string{}, focus, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tif _, err := call(h.ctx, focusAction, opts.Timeout); err != nil {\n\t\treturn fmt.Errorf(\"focusing on element: %w\", err)","sourceCodeStart":898,"sourceCodeEnd":934,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L898-L934","documentation":"Returned by ElementHandle.fill() in the k6 browser module when the fill action cannot complete. Fill first waits for the element to be visible, enabled and editable (unless force:true), then focuses it and sets its value; any failure in that pipeline is wrapped with %w, most commonly a timeout waiting for one of those element states. The wrapped cause carries the real reason (e.g. 'waiting for element to be editable').","triggerScenarios":"handle.fill(value) on an element that is hidden, disabled, or readonly/non-editable when the timeout expires; filling a handle whose node was detached by a SPA re-render; using a handle captured before a page navigation; page or browser closed while the action was retrying.","commonSituations":"React/Vue apps re-rendering between page.$() and fill(); a selector matching a hidden duplicate node instead of the intended input; inputs gated behind UI logic (enabled only after another control changes); default timeout too short on slow CI machines or under k6 load.","solutions":["Wait for actionability before filling: page.waitForSelector(sel, { state: 'visible' }) and confirm the control is enabled and not readonly","Make the selector unique (browser devtools) so it does not resolve to a hidden duplicate","Give the action a bigger budget: handle.fill(value, { timeout: 10000 }) or raise the browser-level timeout option","If the state check is a false negative (CSS opacity/animation quirks), bypass checks with { force: true }","Re-query the handle immediately before fill instead of reusing one captured earlier"],"exampleFix":"// before\nconst h = await page.$('#email');\nawait h.fill('a@b.c');\n// after\nawait page.waitForSelector('#email', { state: 'visible' });\nconst h = await page.$('#email');\nawait h.fill('a@b.c', { timeout: 10000 });","handlingStrategy":"try-catch","validationCode":"const sel = '#email';\nawait page.waitForSelector(sel, { state: 'visible', timeout: 5000 });\nconst h = await page.$(sel);\nconst editable = await h.isEditable();\nconst enabled = await h.isEnabled();\nif (!editable || !enabled) throw new Error('field not fillable');","typeGuard":null,"tryCatchPattern":"try {\n  await handle.fill('a@b.c', { timeout: 10000 });\n} catch (e) {\n  if (String(e).includes('filling element')) {\n    await page.waitForSelector(sel, { state: 'visible' });\n    await handle.fill('a@b.c');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always waitForSelector (visible) between locating an element and acting on it","Never cache handles across awaits that can trigger re-renders; re-query before each action","Set an explicit timeout per action instead of relying on the default","Confirm the control is enabled and not readonly in the app under test"],"tags":["browser","element-handle","fill","actionability","timeout"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}