{"record":{"id":"4d23b76319673754","repo":"grafana/k6","slug":"selecting-option-on-q-w","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/frame.go","lineNumber":1706,"sourceCode":"\tact := f.newAction(\n\t\tselector, DOMElementStateAttached, opts.Strict, press,\n\t\t[]string{}, false, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tif _, err := call(f.ctx, act, opts.Timeout); err != nil {\n\t\treturn errorFromDOMError(err)\n\t}\n\n\treturn nil\n}\n\n// SelectOption selects the given options and returns the array of\n// option values of the first element found that matches the selector.\nfunc (f *Frame) SelectOption(selector string, values []any, popts *FrameSelectOptionOptions) ([]string, error) {\n\tf.log.Debugf(\"Frame:SelectOption\", \"fid:%s furl:%q sel:%q\", f.ID(), f.URL(), selector)\n\n\tv, err := f.selectOption(selector, values, popts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"selecting option on %q: %w\", selector, err)\n\t}\n\n\tapplySlowMo(f.ctx)\n\n\treturn v, nil\n}\n\nfunc (f *Frame) selectOption(selector string, values []any, opts *FrameSelectOptionOptions) ([]string, error) {\n\tselectOption := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.selectOption(apiCtx, values)\n\t}\n\tact := f.newAction(\n\t\tselector, DOMElementStateAttached, opts.Strict, selectOption,\n\t\t[]string{}, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tv, err := call(f.ctx, act, opts.Timeout)\n\tif err != nil {\n\t\treturn nil, errorFromDOMError(err)","sourceCodeStart":1688,"sourceCodeEnd":1724,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L1688-L1724","documentation":"Frame.SelectOption() wraps the internal select-option action; any failure — element not found, not a <select> element, actionability timeout, or a mid-action detach — is reported as 'selecting option on \"<selector>\": <cause>'. The actionable detail is the wrapped cause, not the prefix.","triggerScenarios":"frame.selectOption(sel, values) where sel does not match a <select> element (e.g. a custom div dropdown), the select is hidden/disabled, values do not match any option, or strict mode finds multiple matches. Also when the element detaches between resolution and click.","commonSituations":"Modern UIs use div/role=listbox dropdowns where selectOption cannot work — a real <select> is required; selecting by value when the option only has a label; hidden native selects styled with display:none (materialize/bootstrap overrides).","solutions":["Confirm the target is a real <select> element (inspect with evaluate(() => document.querySelector(sel).tagName)); if it is a custom widget, click it and click options instead.","Pass the right matcher shape: { value: 'x' }, { label: 'Text' }, or { index: 2 }.","Wait for the select to be visible/enabled before the call.","If the select is styled but native, use { force: true } to bypass visibility checks."],"exampleFix":"// before\nawait frame.selectOption('.nice-select', 'opt1'); // div wrapper, not <select>\n\n// after\nawait frame.selectOption('select#country', { value: 'opt1' });\n// or for custom dropdowns:\nawait frame.click('.dropdown-toggle');\nawait frame.click('li[data-value=\"opt1\"]');","handlingStrategy":"validation","validationCode":"const tag = await frame.evaluate(s => document.querySelector(s)?.tagName, sel);\nif (tag !== 'SELECT') throw new Error(`${sel} is ${tag}, not <select>`);","typeGuard":"const isNativeSelect = (t) => t === 'SELECT';","tryCatchPattern":"try { await frame.selectOption(sel, { value: v }); }\ncatch (e) { if (/selecting option on/.test(e.message)) { /* check tagName, matcher shape, visibility */ } throw e; }","preventionTips":["Confirm the target is a real <select> element before calling","Pass { value } / { label } / { index } matchers, not raw guesses","For custom dropdown widgets, click through options instead"],"tags":["browser","form","select","actionability","selector"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}