{"record":{"id":"7e50708eb043b107","repo":"grafana/k6","slug":"getting-element-s-input-value-w","errorCode":null,"errorMessage":"getting element's input value: %w","messagePattern":"getting element's input value: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1042,"sourceCode":"\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)\n\tv, err := call(h.ctx, inputValueAction, opts.Timeout)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"getting element's input value: %w\", err)\n\t}\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// IsChecked checks if a checkbox or radio is checked.\nfunc (h *ElementHandle) IsChecked() (bool, error) {\n\tok, err := h.isChecked(h.ctx, 0)\n\t// We don't care about timeout errors here!\n\tif err != nil && !errors.Is(err, ErrTimedOut) {\n\t\treturn false, fmt.Errorf(\"checking element is checked: %w\", err)\n\t}\n","sourceCodeStart":1024,"sourceCodeEnd":1060,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L1024-L1060","documentation":"ElementHandle.inputValue() wraps the failure of a CDP evaluation whose injected JavaScript explicitly throws 'Node is not an <input>, <textarea> or <select> element' for wrong node types, plus the usual evaluation failures (stale handle, destroyed context, timeout).","triggerScenarios":"Calling inputValue() on a button, div, span, or any element that is not input/textarea/select; the handle resolves to a component wrapper (shadow-DOM host, kendo/material wrapper) instead of the inner field; the element detached before the evaluation ran.","commonSituations":"Custom UI components where the real input lives in shadow DOM or deeper in the tree; form libraries that render custom widgets; mistaking a label or container for the input.","solutions":["Select the actual input/textarea/select element (poke into shadow DOM or use a more specific selector)","Verify the node first: await el.evaluate(e => /^(INPUT|TEXTAREA|SELECT)$/.test(e.nodeName))","If you just need the value, fall back to await el.evaluate(e => e.value)","Re-acquire the handle if a re-render may have detached it"],"exampleFix":"// before\nconst el = await page.$('.x-field');\nconst v = await el.inputValue(); // wrapper div is not an input\n\n// after\nconst el = await page.$('.x-field input, .x-field textarea, .x-field select');\nconst v = await el.inputValue();","handlingStrategy":"validation","validationCode":"// Confirm the node is a value-bearing control before inputValue()\nconst isField = await el.evaluate(\n  (e) => /^(INPUT|TEXTAREA|SELECT)$/.test(e.nodeName)\n);\nif (!isField) {\n  throw new Error('not an input/textarea/select; target the real field');\n}\nconst v = await el.inputValue();","typeGuard":null,"tryCatchPattern":"try {\n  const v = await el.inputValue();\n} catch (e) {\n  if (/not an <input>/i.test(String(e.message))) {\n    const v = await el.evaluate((e2) => String(e2.value ?? '')); // raw value read\n  } else throw e;\n}","preventionTips":["Select the inner native control of custom components, not the wrapper","Check nodeName when components conditionally render different field types"],"tags":["browser","input-value","form","dom","k6"],"backgroundTag":"element-not-input","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"}