{"record":{"id":"467bb57105358c2a","repo":"grafana/k6","slug":"getting-input-value-of-q-w-467bb5","errorCode":null,"errorMessage":"getting input value of %q: %w","messagePattern":"getting input value of %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/locator.go","lineNumber":515,"sourceCode":"\n\topts.Strict = true\n\ts, ok, err := l.frame.textContent(l.selector, opts)\n\tif err != nil {\n\t\treturn \"\", false, fmt.Errorf(\"getting text content of %q: %w\", l.selector, err)\n\t}\n\n\treturn s, ok, nil\n}\n\n// InputValue returns the element's input value that matches\n// the locator's selector with strict mode on.\nfunc (l *Locator) InputValue(opts *FrameInputValueOptions) (string, error) {\n\tl.log.Debugf(\"Locator:InputValue\", \"fid:%s furl:%q sel:%q opts:%+v\", l.frame.ID(), l.frame.URL(), l.selector, opts)\n\n\topts.Strict = true\n\tv, err := l.frame.inputValue(l.selector, opts)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"getting input value of %q: %w\", l.selector, err)\n\t}\n\n\treturn v, nil\n}\n\n// SelectOption filters option values of the first element that matches\n// the locator's selector (with strict mode on), selects the options,\n// and returns the filtered options.\nfunc (l *Locator) SelectOption(values []any, opts *FrameSelectOptionOptions) ([]string, error) {\n\tl.log.Debugf(\"Locator:SelectOption\", \"fid:%s furl:%q sel:%q opts:%+v\", l.frame.ID(), l.frame.URL(), l.selector, opts)\n\n\topts.Strict = true\n\tv, err := l.frame.selectOption(l.selector, values, opts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"selecting option on %q: %w\", l.selector, err)\n\t}\n\n\tapplySlowMo(l.ctx)","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/locator.go#L497-L533","documentation":"Thrown by Locator.InputValue() in the k6 browser module when the wrapped frame.inputValue call fails. Strict mode is forced on, so the selector must resolve to exactly one element. Zero matches before the timeout, multiple matches (strict mode violation), or an element that is not <input>/<textarea>/<select> all fail; the wrapped error carries the underlying cause.","triggerScenarios":"locator.inputValue() where the selector matches 0 elements (timeout expires), matches more than 1 element (strict mode violation), or resolves to a non-input element such as <div> or contenteditable.","commonSituations":"Broad selectors like 'input' or '.field' that match several elements; reading a value before SPA rendering finishes; calling inputValue on a container instead of the actual form control.","solutions":["Make the selector unique (add id/data-testid, chain getByName/getByLabel, or use nth()) so exactly one element matches","await locator.waitFor() before calling inputValue() so the element exists","Confirm the target element is an <input>, <textarea>, or <select>","Increase opts.timeout if the element appears late in the page lifecycle"],"exampleFix":"// before\nconst v = await page.locator('input').inputValue(); // multiple inputs -> strict mode violation\n\n// after\nawait page.locator('input[name=\"email\"]').waitFor();\nconst v = await page.locator('input[name=\"email\"]').inputValue();","handlingStrategy":"try-catch","validationCode":"const inputs = await page.$$('input[name=\"email\"]');\nif (inputs.length !== 1) {\n  throw new Error(`expected 1 input, found ${inputs.length}`);\n}\nconst v = await page.locator('input[name=\"email\"]').inputValue();","typeGuard":"function isInputLike(el) {\n  if (!el) return false;\n  const t = el.tagName ? el.tagName.toLowerCase() : '';\n  return t === 'input' || t === 'textarea' || t === 'select';\n}","tryCatchPattern":"try {\n  const v = await page.locator(sel).inputValue();\n} catch (e) {\n  if (/strict mode violation/i.test(e.message)) {\n    // selector matched multiple elements: narrow it\n  } else if (/timeout/i.test(e.message)) {\n    // element never appeared: wait longer or fix selector\n  } else { throw e; }\n}","preventionTips":["Prefer getByRole/getByLabel/getByTestId over bare tag selectors","Standardize on data-testid attributes in the app under test","Call waitFor() before reading values on dynamically rendered pages"],"tags":["browser","locator","strict-mode","dom","input"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}