grafana/k6 · error
parsing waitForElementState options
Error message
parsing waitForElementState options: %w
What it means
Thrown when ElementHandle.waitForElementState cannot parse its options. ElementHandleWaitForElementStateOptions.Parse reads only the timeout key, coerces it with ToInteger, and ignores unknown keys, so this error wrap has no realistic trigger in the current code. An invalid state string is validated later inside WaitForElementState and produces a different error.
Solutions
- Pass options as a plain object with a numeric timeout, or omit them
- If you meant to fix an invalid-state failure, use one of attached|detached|visible|hidden in the first argument
- Inspect the wrapped error after the colon for the true cause
Example fix
// before
await handle.waitForElementState('visible', '3000');
// after
await handle.waitForElementState('visible', { timeout: 3000 }); Defensive patterns
Strategy: try-catch
Validate before calling
const states = ['attached', 'detached', 'visible', 'hidden'];
if (!states.includes(state)) throw new Error(`state must be one of ${states.join('|')}`);
await handle.waitForElementState(state, { timeout: Number(timeoutMs) }); Try / catch
try {
await handle.waitForElementState(state, opts);
} catch (e) {
if (String(e).includes('parsing waitForElementState options')) {
await handle.waitForElementState(state); // retry with defaults
} else { throw e; }
} Prevention
- Restrict state to attached|detached|visible|hidden — validated later, but worth pre-checking
- Keep timeout numeric
- Don't confuse this parse error with the separate invalid-state error
When it happens
Trigger: Calling waitForElementState('visible', opts) with an opts value that cannot be converted to an object (e.g. a Symbol) — ordinary objects, numbers-in-strings, null and undefined all coerce fine.
Common situations: Practically never occurs; note that passing a bad state like 'enabled' fails elsewhere with a state-validation message, which users often mistake for this parse error.
Related errors
- parsing element tap options
- parsing setChecked options
- parsing setInputFiles options
- parsing type options
- parsing uncheck options
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-09-14).
Data as JSON: /api/errors/aa5f565ed380147c.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/element_handle_mapping.go:292
return nil, fmt.Errorf("parsing type options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, eh.Type(text, popts) //nolint:wrapcheck
}), nil
},
"uncheck": func(opts sobek.Value) (*sobek.Promise, error) {
popts, err := parseElementHandleSetCheckedOptions(rt, opts, eh.DefaultTimeout())
if err != nil {
return nil, fmt.Errorf("parsing uncheck options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, eh.Uncheck(popts) //nolint:wrapcheck
}), nil
},
"waitForElementState": func(state string, opts sobek.Value) (*sobek.Promise, error) {
popts, err := parseElementHandleWaitForElementStateOptions(rt, opts, eh.DefaultTimeout())
if err != nil {
return nil, fmt.Errorf("parsing waitForElementState options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, eh.WaitForElementState(state, popts) //nolint:wrapcheck
}), nil
},
"waitForSelector": func(selector string, opts sobek.Value) (*sobek.Promise, error) {
popts, err := parseFrameWaitForSelectorOptions(rt, opts, eh.DefaultTimeout())
if err != nil {
return nil, fmt.Errorf("parsing waitForSelector %q options: %w", selector, err)
}
return promise(vu, func() (any, error) {
eh, err := eh.WaitForSelector(selector, popts)
if err != nil {
return nil, err //nolint:wrapcheck
}
return mapElementHandle(vu, eh), nil
}), nil
},View on GitHub (pinned to 3fcf5388d7)