grafana/k6 · error
invalid argument, cannot use a '%T' as a selector
Error message
invalid argument, cannot use a '%T' as a selector
What it means
A k6/html selection method (Find, Add, Closest, Has, Not...) received a selector argument that is neither a Selection, string, Element nor a nested value. varargFnCall's default branch panics with a Go error surfaced to the JS runtime.
Solutions
- Pass a CSS selector string, an Element, or a Selection as the argument
- Wrap the value in a string, e.g. page.find('div.item') instead of an object
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at js/modules/k6/html/html.go:112 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/6e160dd4166fbd00.
Report an issue: GitHub.
Appendix: source
Thrown at js/modules/k6/html/html.go:112
strFilter func(string) *goquery.Selection,
selFilter func(*goquery.Selection) *goquery.Selection,
nodeFilter func(...*gohtml.Node) *goquery.Selection,
) Selection {
switch v := arg.(type) {
case Selection:
return Selection{s.rt, selFilter(v.sel), s.URL}
case string:
return Selection{s.rt, strFilter(v), s.URL}
case Element:
return Selection{s.rt, nodeFilter(v.node), s.URL}
case sobek.Value:
return s.varargFnCall(v.Export(), strFilter, selFilter, nodeFilter)
default:
err := fmt.Errorf("invalid argument, cannot use a '%T' as a selector", arg)
panic(s.rt.NewGoError(err))
}
}
func (s Selection) adjacent(unfiltered func() *goquery.Selection,
filtered func(string) *goquery.Selection,
def ...string,
) Selection {
if len(def) > 0 {
return Selection{s.rt, filtered(def[0]), s.URL}
}
return Selection{s.rt, unfiltered(), s.URL}
}
func (s Selection) adjacentUntil(until func(string) *goquery.Selection,
untilSelection func(*goquery.Selection) *goquery.Selection,
filteredUntil func(string, string) *goquery.Selection,View on GitHub (pinned to 01ffac6f24)