{"record":{"id":"09f165ab8e5f9344","repo":"CloakHQ/CloakBrowser","slug":"elementnotattachederror-sourceselector","errorCode":null,"errorMessage":"ElementNotAttachedError: {sourceSelector}","messagePattern":"ElementNotAttachedError: (.+?)","errorType":"exception","errorClass":"ElementNotAttachedError","httpStatus":null,"severity":"error","filePath":"dotnet/src/CloakBrowser/Human/HumanPage.cs","lineNumber":636,"sourceCode":"        return scroll.DidScroll;\n    }\n\n    // -----------------------------------------------------------------------\n    // Drag-and-drop (humanized: move to source center, down, move to target, up)\n    // -----------------------------------------------------------------------\n\n    /// <summary>Human-like drag from <paramref name=\"sourceSelector\"/> to\n    /// <paramref name=\"targetSelector\"/>. Port of <c>_frame_drag_and_drop</c> / <c>_humanized_drag_to</c>:\n    /// moves to the source center, presses, moves to the target center, releases.</summary>\n    public async Task DragAndDropAsync(string sourceSelector, string targetSelector, HumanActionOptions? options = null)\n    {\n        await EnsureCursorInitAsync().ConfigureAwait(false);\n        double timeout = options?.Timeout ?? 30000;\n\n        var srcBox = await GetBoxAsync(sourceSelector, timeout).ConfigureAwait(false);\n        var tgtBox = await GetBoxAsync(targetSelector, timeout).ConfigureAwait(false);\n        if (srcBox == null)\n            throw new ElementNotAttachedError(sourceSelector);\n        if (tgtBox == null)\n            throw new ElementNotAttachedError(targetSelector);\n\n        BoundingBox src = srcBox.Value;\n        BoundingBox tgt = tgtBox.Value;\n        double sx = src.X + src.Width / 2;\n        double sy = src.Y + src.Height / 2;\n        double tx = tgt.X + tgt.Width / 2;\n        double ty = tgt.Y + tgt.Height / 2;\n\n        await HumanMouse.HumanMoveAsync(_rawMouse, _cursor.X, _cursor.Y, sx, sy, _cfg).ConfigureAwait(false);\n        _cursor.X = sx; _cursor.Y = sy;\n        await HumanRandom.SleepMsAsync(HumanRandom.Rand(100, 200)).ConfigureAwait(false);\n        await _rawMouse.DownAsync().ConfigureAwait(false);\n        await HumanRandom.SleepMsAsync(HumanRandom.Rand(80, 150)).ConfigureAwait(false);\n        await HumanMouse.HumanMoveAsync(_rawMouse, _cursor.X, _cursor.Y, tx, ty, _cfg).ConfigureAwait(false);\n        _cursor.X = tx; _cursor.Y = ty;\n        await HumanRandom.SleepMsAsync(HumanRandom.Rand(80, 150)).ConfigureAwait(false);","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/CloakHQ/CloakBrowser/blob/d6bad5de261bedf025280ace1d14e800aee13923/dotnet/src/CloakBrowser/Human/HumanPage.cs#L618-L654","documentation":"Thrown by the humanized drag-and-drop flow in HumanPage when the SOURCE element's bounding box cannot be resolved within the timeout. It means GetBoxAsync returned null for the source selector, so the drag cannot compute a start point.","triggerScenarios":"Calling HumanPage drag APIs (e.g. DragAsync(sourceSelector, targetSelector, options)) where the source selector matches no attached element within options.Timeout (default 30000 ms), or the element is detached/hidden when the box is queried.","commonSituations":"Selector typo, element rendered late (SPA), element inside an iframe or shadow root the selector doesn't reach, or a too-short options.Timeout passed by the caller.","solutions":["Verify the source selector matches exactly one attached element (test with page.QuerySelectorAsync first or a Playwright locator)","Wait for the element to be visible before dragging (page.WaitForSelectorAsync with state Visible)","Increase options.Timeout","If the element is in a frame/shadow DOM, use a selector scoped to that context"],"exampleFix":"// before\nawait page.DragAsync(\"#src\", \"#dst\");\n\n// after\nawait page.WaitForSelectorAsync(\"#src\", new() { State = WaitForSelectorState.Visible });\nawait page.DragAsync(\"#src\", \"#dst\", new DragOptions { Timeout = 60000 });","handlingStrategy":"validation","validationCode":"var el = await page.QuerySelectorAsync(sourceSelector);\nif (el == null) throw new InvalidOperationException($\"source missing: {sourceSelector}\");","typeGuard":null,"tryCatchPattern":"catch (ElementNotAttachedError e) when (e.Message.Contains(sourceSelector)) { /* re-wait and retry once */ }","preventionTips":["Wait for source element visibility before drag calls","Prefer stable data-testid selectors","Pass an explicit generous Timeout in drag options"],"tags":["humanize","drag-and-drop","element-not-found","playwright"],"backgroundTag":"element-not-found","analyzedSha":"d6bad5de261bedf025280ace1d14e800aee13923","analyzedAt":"2026-08-28T14:13:12.918Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}