{"record":{"id":"e6c459ecb5351312","repo":"grafana/k6","slug":"selecting-option-on-q-w-e6c459","errorCode":null,"errorMessage":"selecting option on %q: %w","messagePattern":"selecting option on %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/locator.go","lineNumber":530,"sourceCode":"\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)\n\n\treturn v, nil\n}\n\n// Press the given key on the element found that matches the locator's\n// selector with strict mode on.\nfunc (l *Locator) Press(key string, opts *FramePressOptions) error {\n\tl.log.Debugf(\n\t\t\"Locator:Press\", \"fid:%s furl:%q sel:%q key:%q opts:%+v\",\n\t\tl.frame.ID(), l.frame.URL(), l.selector, key, opts,\n\t)\n\n\topts.Strict = true\n\tif err := l.frame.press(l.selector, key, opts); err != nil {\n\t\treturn fmt.Errorf(\"pressing %q on %q: %w\", key, l.selector, err)","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/locator.go#L512-L548","documentation":"Thrown by Locator.SelectOption() when the wrapped frame.selectOption call fails. Strict mode is forced on, so exactly one element must match. Typical underlying failures: strict mode violation (multiple matches), timeout waiting for the <select> to be actionable, or the resolved element not being a <select> element at all.","triggerScenarios":"locator.selectOption(...) where the selector matches 0 or >1 elements, the element is not a <select>, or the select is disabled/hidden past the timeout so it never becomes actionable.","commonSituations":"Selecting from a dropdown rendered asynchronously (React/Vue select); selectors like 'select' matching several dropdowns on a form; passing values whose options are not present so nothing can be selected; custom dropdown widgets that use <div>/<ul> instead of <select>.","solutions":["Use a selector that matches exactly one <select> (add id or data-testid)","await locator.waitFor() first so the dropdown is rendered","Verify the target is a real <select> element, not a custom div-based dropdown","Match the option exactly by value or label (inspect the option elements first)"],"exampleFix":"// before\nawait page.locator('select').selectOption('DE'); // multiple selects -> strict mode violation\n\n// after\nawait page.locator('select#country').waitFor();\nawait page.locator('select#country').selectOption({ value: 'DE' });","handlingStrategy":"try-catch","validationCode":"const selects = await page.$$('select#country');\nif (selects.length !== 1) throw new Error(`expected one select, found ${selects.length}`);\nawait page.locator('select#country').selectOption({ value: 'DE' });","typeGuard":"async function isSelectElement(page, sel) {\n  const el = await page.$(sel);\n  return !!el && (await el.getProperty('tagName')).jsonValue() === 'SELECT';\n}","tryCatchPattern":"try {\n  await page.locator(sel).selectOption(values);\n} catch (e) {\n  if (/strict mode violation/i.test(e.message)) { /* narrow selector */ }\n  else if (/not a select/i.test(e.message)) { /* custom dropdown: click options instead */ }\n  else throw e;\n}","preventionTips":["Verify in devtools that the dropdown is a real <select> before scripting","Use exact value/label objects ({value:'x'}) instead of guessing","For custom div-dropdowns, click the option elements instead of selectOption"],"tags":["browser","locator","strict-mode","select","form"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}