{"record":{"id":"ce508b3697d4cd27","repo":"segment-boneyard/nightmare","slug":"unable-to-find-element-by-selector-selector","errorCode":null,"errorMessage":"Unable to find element by selector: ${selector}","messagePattern":"Unable to find element by selector: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/actions.js","lineNumber":110,"sourceCode":"    selector\n  )\n}\n\n/**\n * Click an element.\n *\n * @param {String} selector\n * @param {Function} done\n */\n\nexports.click = function(selector, done) {\n  debug('.click() on ' + selector)\n  this.evaluate_now(\n    function(selector) {\n      document.activeElement.blur()\n      var element = document.querySelector(selector)\n      if (!element) {\n        throw new Error('Unable to find element by selector: ' + selector)\n      }\n      var bounding = element.getBoundingClientRect()\n      var event = new MouseEvent('click', {\n        view: document.window,\n        bubbles: true,\n        cancelable: true,\n        clientX: bounding.left + bounding.width / 2,\n        clientY: bounding.top + bounding.height / 2\n      })\n      element.dispatchEvent(event)\n    },\n    done,\n    selector\n  )\n}\n\n/**\n * Mousedown on an element.","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/segment-boneyard/nightmare/blob/0f47de84991243cc040e8e020f7aee847c7c4a0e/lib/actions.js#L92-L128","documentation":"Thrown inside Nightmare's click action when the serialized DOM query runs in the page context: document.querySelector(selector) returns null, so the guard rejects the click. It means the selector string passed to .click() matched zero elements in the current DOM at click time — typically because the page hasn't finished rendering, the selector is misspelled, or the element lives inside a frame that wasn't targeted.","triggerScenarios":"Thrown at lib/actions.js:110 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the selector manually in the page's devtools with document.querySelector before using it in the script","Wait for the element to exist before clicking, e.g. add .wait(selector) before .click(selector) in the Nightmare chain","Correct typos or stale class/id names in the selector; re-inspect the live DOM since markup may have changed","If the element is inside an iframe or shadow DOM, switch context to that frame before querying","Increase the wait/delay so the page's JavaScript has finished rendering the element"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0f47de84991243cc040e8e020f7aee847c7c4a0e","analyzedAt":"2026-09-02T12:06:19.701Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}