{"record":{"id":"7d94bbe198ad856a","repo":"jackwener/OpenCLI","slug":"could-not-locate-midjourney-slotlabel-slot-afte","errorCode":null,"errorMessage":"Could not locate Midjourney ${slotLabel} slot after upload","messagePattern":"Could not locate Midjourney (.+?) slot after upload","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":1069,"sourceCode":"    document.querySelectorAll('[data-opencli-ref-source],[data-opencli-ref-target]').forEach((el) => {\n      el.removeAttribute('data-opencli-ref-source');\n      el.removeAttribute('data-opencli-ref-target');\n    });\n    const source = [...document.querySelectorAll('img[src]')].find((img) => img.src === url);\n    const labelNode = [...document.querySelectorAll('div,span')].find((node) => node.children.length === 0 && node.textContent?.trim() === label);\n    if (!source || !labelNode) return { ok: false, source: Boolean(source), target: Boolean(labelNode) };\n    let target = labelNode.parentElement;\n    while (target && target.parentElement) {\n      const rect = target.getBoundingClientRect();\n      if (rect.width >= 120 && rect.height >= 45) break;\n      target = target.parentElement;\n    }\n    if (!target) return { ok: false, source: true, target: false };\n    source.setAttribute('data-opencli-ref-source', '1');\n    target.setAttribute('data-opencli-ref-target', '1');\n    return { ok: true };\n  }, sourceUrl, slotLabel));\n  if (!result?.ok) throw new CommandExecutionError(`Could not locate Midjourney ${slotLabel} slot after upload`);\n}\n\nasync function verifyReferenceTarget(page, slotLabel) {\n  const assigned = unwrapEvaluateResult(await page.evaluate((label) => {\n    const labelNode = [...document.querySelectorAll('div,span')]\n      .find((node) => node.children.length === 0 && node.textContent?.trim() === label);\n    if (!labelNode) return false;\n    const peerLabels = ['Image Prompts', 'Style References', 'Omni Reference'].filter((item) => item !== label);\n    let target = labelNode;\n    for (let depth = 0; depth < 8 && target?.parentElement; depth += 1) {\n      target = target.parentElement;\n      const text = target.textContent || '';\n      if (peerLabels.some((peer) => text.includes(peer))) break;\n      const empty = [...target.querySelectorAll('div')]\n        .some((node) => /^Select images? below$/i.test(node.textContent?.trim() || ''));\n      if (!empty && target.querySelector('button,img')) return true;\n    }\n    return false;","sourceCodeStart":1051,"sourceCodeEnd":1087,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L1051-L1087","documentation":"Thrown when markReferenceTarget cannot find the target drop area (slot) for the given slotLabel after uploading a reference image. The in-page evaluate returns {ok:false, source:true, target:false} because no matching slot element was located in the Midjourney composer.","triggerScenarios":"Calling uploadReferencesToSlot / markReferenceTarget when the reference slot panel is closed, the slot label changed, or the panel DOM has not rendered yet.","commonSituations":"Image panel not opened before marking; Midjourney renamed slot labels (e.g. 'Style References'); slow rendering so slots are absent; page in a different state (no draft open).","solutions":["Ensure openImagePanel(page) ran and the image panel is visible before marking slots.","Log/dump the slot DOM to verify the current slot label text and update slotLabel mapping.","Add a wait/retry before evaluate so the slot element has rendered.","Reload the Midjourney page and open a fresh composer."],"exampleFix":"// before\nawait markReferenceTarget(page, url, label);\n// after\nawait openImagePanel(page);\nawait page.wait(1);\nawait markReferenceTarget(page, url, label);","handlingStrategy":"validation","validationCode":"const hasSlot = await page.evaluate((label) =>\n  [...document.querySelectorAll('div,span')].some(n => n.textContent?.trim() === label), slotLabel);\nif (!hasSlot) await openImagePanel(page);","typeGuard":null,"tryCatchPattern":"try {\n  await markReferenceTarget(page, url, label);\n} catch (err) {\n  if (String(err.message).includes('Could not locate')) {\n    await openImagePanel(page);\n    await markReferenceTarget(page, url, label);\n  } else throw err;\n}","preventionTips":["Always open the image panel first","Verify slot label text against the live UI","Add waits for panel rendering","Reload the page if slots are missing"],"tags":["midjourney","dom","selector","browser-automation"],"backgroundTag":"dom-element-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}