{"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":1429,"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":1411,"sourceCodeEnd":1447,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L1411-L1447","documentation":"Thrown by the k6 browser module's ElementHandle.selectOption(). It wraps any failure of the selectOption action: the timeout expiring, the wrapped element being detached, or the injected script returning a DOM error string that errorFromDOMError translates, most commonly 'element is not a <select> element' (error:notselect).","triggerScenarios":"Calling el.selectOption(['opt1']) on anything other than a <select> element (a div styled as a dropdown, a custom combobox); on a <select> that is re-rendered and detached before the action runs; on a detached/stale handle; with a timeout shorter than the page's render time.","commonSituations":"Modern component libraries (MUI, Ant Design) that render fake dropdowns with <ul><li> instead of native <select>; React re-rendering the select and invalidating the handle; option value mismatch is NOT this error (that silently selects nothing) — this error is about the target node itself.","solutions":["Verify the target is a real native <select> element: check (await el.getProperty('tagName')).jsonValue() === 'SELECT'; for custom dropdowns use click() + click() on options instead.","Re-query the element handle right before the call so it is attached: el = await page.waitForSelector('select#country', { state: 'visible' }).","Increase the timeout: el.selectOption(['de'], { timeout: '60s' }).","Pass { force: true } to skip actionability checks if the element is present but flaky about visibility/stability."],"exampleFix":"// before\nconst dropdown = await page.$('.my-dropdown'); // a styled <div>, not a <select>\nawait dropdown.selectOption(['de']); // error: element is not a <select> element\n\n// after\nconst dropdown = await page.waitForSelector('select#country');\nawait dropdown.selectOption(['de'], { timeout: '30s' });","handlingStrategy":"validation","validationCode":"const tag = await el.getProperty('tagName').then(p => p.jsonValue());\nif (tag !== 'SELECT') {\n  throw new Error(`selectOption requires a <select>, got <${tag}>`);\n}\nawait el.selectOption(['de'], { timeout: '30s' });","typeGuard":"async function isNativeSelect(el) {\n  if (!el) return false;\n  const tag = await el.getProperty('tagName').then(p => p.jsonValue()).catch(() => null);\n  return tag === 'SELECT';\n}","tryCatchPattern":"try {\n  await el.selectOption(['de'], { timeout: '30s' });\n} catch (e) {\n  if (String(e).includes('not a <select>')) { /* drive custom dropdown via clicks */ }\n  else { throw e; }\n}","preventionTips":["Verify the target renders a native <select> before scripting selectOption; component-library dropdowns usually need click sequences.","Include a tagName assertion in test setup for dropdown targets so a markup change fails fast with a clear message."],"tags":["k6","browser","element-handle","select","wrong-element-type"],"backgroundTag":"element-wrong-type","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"}