{"record":{"id":"d515710a1d705421","repo":"CloakHQ/CloakBrowser","slug":"elementnotattachederror-targetselector","errorCode":null,"errorMessage":"ElementNotAttachedError: {targetSelector}","messagePattern":"ElementNotAttachedError: (.+?)","errorType":"exception","errorClass":"ElementNotAttachedError","httpStatus":null,"severity":"error","filePath":"dotnet/src/CloakBrowser/Human/HumanPage.cs","lineNumber":638,"sourceCode":"\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);\n        await _rawMouse.UpAsync().ConfigureAwait(false);\n    }","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/CloakHQ/CloakBrowser/blob/d6bad5de261bedf025280ace1d14e800aee13923/dotnet/src/CloakBrowser/Human/HumanPage.cs#L620-L656","documentation":"Thrown by the humanized drag-and-drop flow when the TARGET element's bounding box cannot be resolved within the timeout. GetBoxAsync returned null for the target selector, so the drop destination point is unknown.","triggerScenarios":"Calling HumanPage drag APIs where the target selector matches nothing attached within options.Timeout (default 30000 ms), e.g. the drop zone only appears after dragging starts but is queried up front.","commonSituations":"Drop zones that render lazily or only after hover/drag events, selector typos in the target, hidden/zero-size target elements, or short timeouts.","solutions":["Confirm the target element exists and is visible before the drag call","Ensure the drop zone is rendered unconditionally before the drag begins (it is queried before any mouse motion)","Increase options.Timeout","Fix or scope the target selector (frames/shadow DOM)"],"exampleFix":"// before\nawait page.DragAsync(\"#src\", \"#dropzone\");\n\n// after\nawait page.WaitForSelectorAsync(\"#dropzone\", new() { State = WaitForSelectorState.Visible });\nawait page.DragAsync(\"#src\", \"#dropzone\");","handlingStrategy":"validation","validationCode":"var tgt = await page.QuerySelectorAsync(targetSelector);\nif (tgt == null) throw new InvalidOperationException($\"target missing: {targetSelector}\");","typeGuard":null,"tryCatchPattern":"catch (ElementNotAttachedError e) when (e.Message.Contains(targetSelector)) { /* ensure drop zone rendered, retry */ }","preventionTips":["Ensure drop zones are rendered before initiating the drag","Wait for target visibility like the source","Scope selectors correctly for frames/shadow DOM"],"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"}