{"record":{"id":"44c218fad361c18a","repo":"grafana/k6","slug":"calling-function-w","errorCode":null,"errorMessage":"calling function: %w","messagePattern":"calling function: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":2369,"sourceCode":"\t// id returns the CDP runtime ID of this execution context.\n\tID() runtime.ExecutionContextID\n}\n\nfunc (f *Frame) runActionOnSelector(\n\tctx context.Context, selector string, strict bool, fn elementHandleActionFunc, nullResponder func() bool,\n) (bool, error) {\n\thandle, err := f.Query(selector, strict)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"query: %w\", err)\n\t}\n\tif handle == nil {\n\t\tf.log.Debugf(\"Frame:runActionOnSelector:nilHandler\", \"fid:%s furl:%q selector:%s\", f.ID(), f.URL(), selector)\n\t\treturn nullResponder(), err\n\t}\n\n\tv, err := fn(ctx, handle)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"calling function: %w\", err)\n\t}\n\n\tbv, ok := v.(bool)\n\tif !ok {\n\t\treturn false, fmt.Errorf(\"unexpected type %T\", v)\n\t}\n\n\treturn bv, nil\n}\n\n//nolint:unparam\nfunc (f *Frame) newAction(\n\tselector string, state DOMElementState, strict bool, fn elementHandleActionFunc, states []string,\n\tforce bool, retry bool, noWaitAfter bool, timeout time.Duration,\n) func(apiCtx context.Context, resultCh chan any, errCh chan error) {\n\t// We execute a frame action in the following steps:\n\t// 1. Find element matching specified selector\n\t// 2. Wait for it to reach specified DOM state","sourceCodeStart":2351,"sourceCodeEnd":2387,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L2351-L2387","documentation":"Thrown by Frame.runActionOnSelector when the query succeeded and a handle was found, but the element action itself (fn(ctx, handle) — the click/type/focus implementation) returned an error. The wrapped error typically comes from CDP: element not visible, not stable, detached during action, or the browser refused the input (for example intercepted by an overlay).","triggerScenarios":"page.click(sel) on an element with zero size or display:none; element re-rendered (detached) between query and action; overlay/toaster intercepting the pointer; page navigating mid-click; actionability checks failing because the element keeps moving.","commonSituations":"Animated buttons (hover effects, sticky headers); SPAs that re-render on every state change invalidating handles; CI headless environments where layout differs; clicking before fonts/layout settle.","solutions":["Wait for the element to be actionable: page.waitForSelector(sel, { state: 'visible' }) before the action","Retry the action — transient detach during SPA rerender usually succeeds on a second attempt with a fresh selector call","If an overlay legitimately intercepts, use { force: true } to bypass actionability checks","Stabilize the app under test (disable animations) rather than fighting the checks"],"exampleFix":"// before\nawait page.click('#save'); // hidden behind a cookie banner\n\n// after\nawait page.waitForSelector('#save', { state: 'visible' });\nawait page.click('#save', { timeout: 30_000 });\n// or bypass overlays when intentional: page.click('#save', { force: true })","handlingStrategy":"retry","validationCode":null,"typeGuard":"function isActionFailure(e) {\n  return e instanceof Error && /calling function/.test(e.message);\n}","tryCatchPattern":"async function clickStable(page, sel, tries = 3) {\n  for (let i = 0; i < tries; i++) {\n    try {\n      await page.waitForSelector(sel, { state: 'visible' });\n      return await page.click(sel);\n    } catch (e) { if (i === tries - 1) throw e; }\n  }\n}","preventionTips":["Wait for visible state before interacting","Retry once on transient detach from SPA rerenders","Use force only when overlay interception is intentional"],"tags":["browser","element-action","click","actionability"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}