grafana/k6 · error
parsing select option values: %w
Error message
parsing select option values: %w
What it means
Thrown when the values argument of locator.selectOption(values, opts) cannot be converted by ConvertSelectOptionValues. Accepted shapes: null/undefined (select nothing... actually returns no options), a plain string (matches value or label), an array of strings and/or descriptor objects {value?: string, label?: string, index?: number}, a single descriptor object, an ElementHandle pointing at an <option>, or a sobek object with value/label/index getters. Any other type or malformed descriptor produces 'parsing select option values: %w' wrapping a specific cause (see errors 495-499).
Source
Thrown at internal/js/modules/k6/browser/browser/locator_mapping.go:362
}), nil
},
"inputValue": func(opts sobek.Value) (*sobek.Promise, error) {
copts := common.NewFrameInputValueOptions(lo.Timeout())
if err := copts.Parse(vu.Context(), opts); err != nil {
return nil, fmt.Errorf("parsing input value options: %w", err)
}
return promise(vu, func() (any, error) {
return lo.InputValue(copts) //nolint:wrapcheck
}), nil
},
"selectOption": func(values sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
copts := common.NewFrameSelectOptionOptions(lo.Timeout())
if err := copts.Parse(vu.Context(), opts); err != nil {
return nil, fmt.Errorf("parsing select option options: %w", err)
}
convValues, err := ConvertSelectOptionValues(vu.Runtime(), values)
if err != nil {
return nil, fmt.Errorf("parsing select option values: %w", err)
}
return promise(vu, func() (any, error) {
return lo.SelectOption(convValues, copts) //nolint:wrapcheck
}), nil
},
"press": func(key string, opts sobek.Value) (*sobek.Promise, error) {
copts := common.NewFramePressOptions(lo.Timeout())
if err := copts.Parse(vu.Context(), opts); err != nil {
return nil, fmt.Errorf("parsing press options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, lo.Press(key, copts) //nolint:wrapcheck
}), nil
},
"pressSequentially": func(text string, opts sobek.Value) (*sobek.Promise, error) {
copts := common.NewFrameTypeOptions(lo.Timeout())
if err := copts.Parse(vu.Context(), opts); err != nil {View on GitHub (pinned to 93accf6570)
Solutions
- Wrap numeric selection in a descriptor: selectOption({ index: 2 }) instead of selectOption(2)
- Ensure every array item is a string or an object with only string value/label and numeric index
- Sanitize external data before passing it: map values to strings or descriptors
- Pass an ElementHandle only when it references an actual <option> element
Example fix
// before
await page.locator('select').selectOption([0, 2]);
// after
await page.locator('select').selectOption([{ index: 0 }, { index: 2 }]); Defensive patterns
Strategy: type-guard
Validate before calling
function normalizeSelectValues(values) {
if (values === null || values === undefined) return values;
if (typeof values === 'string') return values;
if (Array.isArray(values)) {
return values
.filter((v) => v !== null && v !== undefined)
.map((v) => {
if (typeof v === 'string') return v;
if (typeof v === 'number') return { index: v };
if (typeof v === 'object') {
const o = {};
if ('value' in v) o.value = String(v.value);
if ('label' in v && v.label !== null) o.label = String(v.label);
if ('index' in v) o.index = Number(v.index);
return o;
}
throw new TypeError(`Unsupported selectOption item: ${typeof v}`);
});
}
if (typeof values === 'object') return { value: String(values.value ?? ''), label: values.label !== undefined ? String(values.label) : undefined };
throw new TypeError(`Unsupported selectOption values type: ${typeof values}`);
} Type guard
function isSelectOptionValues(v) {
if (v === null || v === undefined || typeof v === 'string') return true;
if (Array.isArray(v)) return v.every((item) =>
typeof item === 'string' ||
(typeof item === 'object' && item !== null &&
(item.value === undefined || typeof item.value === 'string') &&
(item.label === undefined || typeof item.label === 'string') &&
(item.index === undefined || typeof item.index === 'number')));
if (typeof v === 'object') {
return (v.value === undefined || typeof v.value === 'string') &&
(v.label === undefined || typeof v.label === 'string') &&
(v.index === undefined || typeof v.index === 'number');
}
return false;
} Try / catch
try {
await locator.selectOption(values, opts);
} catch (e) {
if (/parsing select option values/.test(String(e.message))) {
throw new Error(`Invalid selectOption values: ${JSON.stringify(values)} (${e.message})`);
}
throw e;
} Prevention
- Never pass raw numbers as values; wrap them as { index: n }
- Filter null/undefined out of data-driven arrays before calling selectOption
- Stringify value/label fields coming from JSON payloads
When it happens
Trigger: selectOption(42) or selectOption(true) — unsupported scalar kind; selectOption([1, 2]) — array items that are neither string nor object; selectOption({ value: 2 }) — descriptor value/label not a string; selectOption(['a', null]) — null item in array.
Common situations: Passing numbers (option indices) directly instead of { index: n } descriptors; data-driven scripts feeding unvalidated API/JSON data into selectOption; assuming Playwright's SelectOption class objects work in k6.
Related errors
- parsing select option options: %w
- options: expected array, got %T
- options: expected string or object, got %T
- options: expected object, got %T
- options: unsupported type %T
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/aae94d3b4965de84.
Report an issue: GitHub.