CloakHQ/CloakBrowser · error · ElementNotAttachedError
ElementNotAttachedError: {targetSelector}
Error message
ElementNotAttachedError: {targetSelector} What it means
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.
Source
Thrown at dotnet/src/CloakBrowser/Human/HumanPage.cs:638
// -----------------------------------------------------------------------
// Drag-and-drop (humanized: move to source center, down, move to target, up)
// -----------------------------------------------------------------------
/// <summary>Human-like drag from <paramref name="sourceSelector"/> to
/// <paramref name="targetSelector"/>. Port of <c>_frame_drag_and_drop</c> / <c>_humanized_drag_to</c>:
/// moves to the source center, presses, moves to the target center, releases.</summary>
public async Task DragAndDropAsync(string sourceSelector, string targetSelector, HumanActionOptions? options = null)
{
await EnsureCursorInitAsync().ConfigureAwait(false);
double timeout = options?.Timeout ?? 30000;
var srcBox = await GetBoxAsync(sourceSelector, timeout).ConfigureAwait(false);
var tgtBox = await GetBoxAsync(targetSelector, timeout).ConfigureAwait(false);
if (srcBox == null)
throw new ElementNotAttachedError(sourceSelector);
if (tgtBox == null)
throw new ElementNotAttachedError(targetSelector);
BoundingBox src = srcBox.Value;
BoundingBox tgt = tgtBox.Value;
double sx = src.X + src.Width / 2;
double sy = src.Y + src.Height / 2;
double tx = tgt.X + tgt.Width / 2;
double ty = tgt.Y + tgt.Height / 2;
await HumanMouse.HumanMoveAsync(_rawMouse, _cursor.X, _cursor.Y, sx, sy, _cfg).ConfigureAwait(false);
_cursor.X = sx; _cursor.Y = sy;
await HumanRandom.SleepMsAsync(HumanRandom.Rand(100, 200)).ConfigureAwait(false);
await _rawMouse.DownAsync().ConfigureAwait(false);
await HumanRandom.SleepMsAsync(HumanRandom.Rand(80, 150)).ConfigureAwait(false);
await HumanMouse.HumanMoveAsync(_rawMouse, _cursor.X, _cursor.Y, tx, ty, _cfg).ConfigureAwait(false);
_cursor.X = tx; _cursor.Y = ty;
await HumanRandom.SleepMsAsync(HumanRandom.Rand(80, 150)).ConfigureAwait(false);
await _rawMouse.UpAsync().ConfigureAwait(false);
}View on GitHub (pinned to d6bad5de26)
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)
Example fix
// before
await page.DragAsync("#src", "#dropzone");
// after
await page.WaitForSelectorAsync("#dropzone", new() { State = WaitForSelectorState.Visible });
await page.DragAsync("#src", "#dropzone"); Defensive patterns
Strategy: validation
Validate before calling
var tgt = await page.QuerySelectorAsync(targetSelector);
if (tgt == null) throw new InvalidOperationException($"target missing: {targetSelector}"); Try / catch
catch (ElementNotAttachedError e) when (e.Message.Contains(targetSelector)) { /* ensure drop zone rendered, retry */ } Prevention
- Ensure drop zones are rendered before initiating the drag
- Wait for target visibility like the source
- Scope selectors correctly for frames/shadow DOM
When it happens
Trigger: 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.
Common situations: Drop zones that render lazily or only after hover/drag events, selector typos in the target, hidden/zero-size target elements, or short timeouts.
Related errors
- ElementNotAttachedError: {sourceSelector}
- Element not found while scrolling into view
- Humanized selector ${selector} is not supported by the isola
- Humanized selector ${selector} is not supported by the isola
- Humanized DOM read requires an active isolated world
AI-assisted analysis of CloakHQ/CloakBrowser@d6bad5de26 (2026-08-28).
Data as JSON: /api/errors/d515710a1d705421.
Report an issue: GitHub.