grafana/k6 · error
clickCount must be an integer, got
Error message
clickCount must be an integer, got %s
What it means
Thrown by parseMouseClickOptions (browser/mouse_mapping.go:82) when mouse.click receives a 'clickCount' option whose Sobek export kind is not Int64. The parser checks v.ExportType().Kind() and only accepts integers; strings ('2'), floats (1.5), booleans, and null all fall to the default branch and report the offending kind in the message.
Solutions
- Pass an integer literal: { clickCount: 2 }.
- Coerce data-driven counts: { clickCount: parseInt(cfg.clickCount, 10) }.
- Validate with Number.isInteger before the call and fail with a clear message.
- Omit clickCount for a single click.
Example fix
// before
await page.mouse().click(10, 20, { clickCount: cfg.clicks }); // "2"
// after
await page.mouse().click(10, 20, { clickCount: parseInt(cfg.clicks, 10) }); Defensive patterns
Strategy: type-guard
Validate before calling
if (opts?.clickCount != null && !Number.isInteger(opts.clickCount)) throw new Error(`clickCount must be an integer, got ${typeof opts.clickCount}`);
await page.mouse().click(x, y, opts); Type guard
function isIntegerOption(o, key) {
return o == null || o[key] == null || Number.isInteger(o[key]);
} Try / catch
try { await page.mouse().click(x, y, opts); } catch (e) { if (/clickCount must be an integer/.test(e.message)) { await page.mouse().click(x, y, { ...opts, clickCount: parseInt(opts.clickCount, 10) }); } else throw e; } Prevention
- Always pass clickCount as an integer literal.
- parseInt data-driven counts at load time.
- Type mouse options in TypeScript ({ clickCount?: number }) to catch strings early.
When it happens
Trigger: page.mouse().click(10, 20, { clickCount: '2' }), { clickCount: 1.5 }, or { clickCount: true }. Note: 2.0 written literally usually exports as int64 and passes; the failure is with genuinely non-integer-typed values.
Common situations: Click counts driven by scenario data (CSV/JSON) where numbers arrive as strings; triple-click helpers parameterized by a count variable; options spread from a shared config object typed loosely.
Related errors
- delay must be an integer, got
- double clicking on element
- hovering on element
- parsing mouse click options
- parsing mouse double click options
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/3759b02d88add49e.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/mouse_mapping.go:82
// parseMouseClickOptions parses the mouse click options from a Sobek value.
func parseMouseClickOptions(rt *sobek.Runtime, opts sobek.Value) (*common.MouseClickOptions, error) {
popts := common.NewMouseClickOptions()
if k6common.IsNullish(opts) {
return popts, nil
}
obj := opts.ToObject(rt)
for _, k := range obj.Keys() {
v := obj.Get(k)
switch k {
case "button":
popts.Button = v.String()
case "clickCount":
switch v.ExportType().Kind() {
case reflect.Int64:
popts.ClickCount = v.ToInteger()
default:
return nil, fmt.Errorf("clickCount must be an integer, got %s", v.ExportType().Kind())
}
case "delay":
switch v.ExportType().Kind() {
case reflect.Int64:
popts.Delay = v.ToInteger()
default:
return nil, fmt.Errorf("delay must be an integer, got %s", v.ExportType().Kind())
}
}
}
return popts, nil
}
// parseMouseDblClickOptions parses the mouse double click options from a Sobek value.
func parseMouseDblClickOptions(rt *sobek.Runtime, opts sobek.Value) (*common.MouseDblClickOptions, error) {
popts := common.NewMouseDblClickOptions()
if k6common.IsNullish(opts) {View on GitHub (pinned to 01ffac6f24)