{"record":{"id":"756465e08bfcdb02","repo":"Kuberwastaken/claurst","slug":"no-element-found-for-selector","errorCode":null,"errorMessage":"No element found for selector: {}","messagePattern":"No element found for selector: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-rust/crates/commands/src/chrome.rs","lineNumber":241,"sourceCode":"                var el=document.querySelector({sel});\r\n                if(!el)return 'ELEMENT_NOT_FOUND';\r\n                var r=el.getBoundingClientRect();\r\n                return JSON.stringify({{x:r.left+r.width/2,y:r.top+r.height/2}});\r\n            }})()\"#,\r\n            sel = sel_json\r\n        );\r\n        let selector = selector.to_string();\r\n        let mut s = take_session()?;\r\n        let result = async {\r\n            let resp = cdp_call(\r\n                &mut s.ws,\r\n                \"Runtime.evaluate\",\r\n                json!({ \"expression\": js, \"returnByValue\": true }),\r\n            )\r\n            .await?;\r\n            let val_str = resp[\"result\"][\"result\"][\"value\"].as_str().unwrap_or(\"\");\r\n            if val_str == \"ELEMENT_NOT_FOUND\" {\r\n                return Err(anyhow::anyhow!(\r\n                    \"No element found for selector: {}\",\r\n                    selector\r\n                ));\r\n            }\r\n            let coords: Value = serde_json::from_str(val_str)?;\r\n            let x = coords[\"x\"].as_f64().unwrap_or(0.0);\r\n            let y = coords[\"y\"].as_f64().unwrap_or(0.0);\r\n\r\n            cdp_call(\r\n                &mut s.ws,\r\n                \"Input.dispatchMouseEvent\",\r\n                json!({\r\n                    \"type\": \"mousePressed\", \"x\": x, \"y\": y,\r\n                    \"button\": \"left\", \"clickCount\": 1\r\n                }),\r\n            )\r\n            .await?;\r\n            cdp_call(\r","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/commands/src/chrome.rs#L223-L259","documentation":"Thrown by the `click` command when the injected Runtime.evaluate JavaScript reports the sentinel value \"ELEMENT_NOT_FOUND\" instead of element coordinates. This means document.querySelector found no match for the given selector in the page DOM, so no click coordinates can be computed.","triggerScenarios":"Calling `/chrome click <selector>` where the selector matches no element in the current tab's DOM; page still loading so the element is not yet rendered; selector typo or wrong frame/iframe context.","commonSituations":"Automating a SPA before hydration completes; clicking an element inside an iframe (querySelector at top level cannot see it); stale selectors after a site redesign; shadow-DOM elements not reachable via plain querySelector.","solutions":["Verify the selector matches in the page (test with `/chrome eval document.querySelector('<selector>') !== null`).","Wait for the page to finish loading before clicking, or navigate explicitly first.","Fix the selector — check for typos, iframes, or shadow-DOM boundaries.","Use a more general selector or add an explicit wait/retry before the click."],"exampleFix":"// before: immediate click on a not-yet-rendered element\nchrome_click(\"#submit\")?;\n\n// after: wait until the element exists\nchrome_eval(\"document.querySelector('#submit') !== null\")?; // poll if false\nchrome_click(\"#submit\")?;","handlingStrategy":"validation","validationCode":"let found: bool = cdp_eval(\"document.querySelector('<selector>') !== null\").await?;\nif !found { /* wait, fix selector, or bail before clicking */ }","typeGuard":"async fn element_exists(ws: &mut Ws, selector: &str) -> bool {\n    let expr = format!(\"document.querySelector({:?}) !== null\", selector);\n    let resp = cdp_call(ws, \"Runtime.evaluate\", json!({\"expression\": expr, \"returnByValue\": true})).await.ok()?;\n    resp[\"result\"][\"result\"][\"value\"].as_bool().unwrap_or(false)\n}","tryCatchPattern":"match click(selector).await {\n    Ok(_) => {},\n    Err(e) if e.to_string().contains(\"No element found\") => {\n        wait_for_selector(selector).await?;\n        click(selector).await?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Test selectors with /chrome eval before scripting clicks.","Wait for SPA rendering/hydration before interacting.","Remember querySelector cannot cross iframe or shadow-DOM boundaries.","Prefer stable ids/data attributes over brittle positional selectors."],"tags":["chrome","dom","selector","cdp"],"backgroundTag":"element-not-found","analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}