{"record":{"id":"bbb6eeaa26ded94f","repo":"grafana/k6","slug":"selecting-options-w","errorCode":null,"errorMessage":"selecting options: %w","messagePattern":"selecting options: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1425,"sourceCode":"\t\treturn fmt.Errorf(\"scrolling element into view: %w\", err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn nil\n}\n\n// SelectOption selects the options matching the given values.\nfunc (h *ElementHandle) SelectOption(values []any, opts *ElementHandleBaseOptions) ([]string, error) {\n\tselectOption := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn handle.selectOption(apiCtx, values)\n\t}\n\tselectOptionAction := h.newAction(\n\t\t[]string{}, selectOption, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,\n\t)\n\tselectedOptions, err := call(h.ctx, selectOptionAction, opts.Timeout)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"selecting options: %w\", err)\n\t}\n\tvar returnVal []string\n\tif err := convert(selectedOptions, &returnVal); err != nil {\n\t\treturn nil, fmt.Errorf(\"unpacking selected options: %w\", err)\n\t}\n\n\tapplySlowMo(h.ctx)\n\n\treturn returnVal, nil\n}\n\n// SelectText selects the text of the element.\nfunc (h *ElementHandle) SelectText(opts *ElementHandleBaseOptions) error {\n\tselectText := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn nil, handle.selectText(apiCtx)\n\t}\n\tselectTextAction := h.newAction(\n\t\t[]string{}, selectText, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,","sourceCodeStart":1407,"sourceCodeEnd":1443,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1407-L1443","documentation":"ElementHandle.SelectOption() wraps the failure of the select action (element_handle.go:1425). The wrapped error is typically 'element is not a select element' from the injected script, an actionability timeout (select hidden/disabled), or no option matching the provided values/labels.","triggerScenarios":"Calling selectOption on a non-<select> element (custom dropdown divs); the select is hidden or disabled; the supplied value/label does not match any option exactly; navigation detaches the element mid-action.","commonSituations":"Custom dropdown components (need click-based interaction, not selectOption); case/whitespace mismatches in labels; selects populated by async fetch after the call runs.","solutions":["Confirm the target is a real <select> element; for custom dropdowns use click() sequences instead","Match options exactly: use option value, or the exact label text; trim dynamic strings","waitForSelector visible and wait for options to be populated before selecting","Raise opts.timeout if the form renders slowly"],"exampleFix":"// before\nawait page.$('select#country').selectOption({ label: 'united states' }); // label mismatch\n// after\nawait page.waitForSelector('select#country option[value=us]');\nawait page.$('select#country').selectOption('us');","handlingStrategy":"validation","validationCode":"// Verify it is a real <select> with a matching option before selecting\nconst ok = await el.evaluate(n => n.tagName === 'SELECT');\nif (!ok) throw new Error('not a select element — use click() for custom dropdowns');","typeGuard":"const isSelect = async el => await el.evaluate(n => n.tagName === 'SELECT');","tryCatchPattern":"try { return await el.selectOption('us', { timeout: 10_000 }); }\ncatch (e) {\n  if (/not a select/.test(e.message)) { /* custom dropdown: click-based flow */ }\n  else if (/selecting options/.test(e.message)) { await page.waitForSelector(`${sel} option[value=us]`); return await el.selectOption('us'); }\n  else throw e;\n}","preventionTips":["Confirm the element is a native <select>","Wait for async options to populate, match values exactly","Use option values over labels to avoid whitespace/case mismatches"],"tags":["browser","form","select","actionability"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}