segment-boneyard/nightmare · error · Error

Unable to find element by selector: ${selector}

Error message

Unable to find element by selector: ${selector}

What it means

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.

Source

Thrown at lib/actions.js:110

    selector
  )
}

/**
 * Click an element.
 *
 * @param {String} selector
 * @param {Function} done
 */

exports.click = function(selector, done) {
  debug('.click() on ' + selector)
  this.evaluate_now(
    function(selector) {
      document.activeElement.blur()
      var element = document.querySelector(selector)
      if (!element) {
        throw new Error('Unable to find element by selector: ' + selector)
      }
      var bounding = element.getBoundingClientRect()
      var event = new MouseEvent('click', {
        view: document.window,
        bubbles: true,
        cancelable: true,
        clientX: bounding.left + bounding.width / 2,
        clientY: bounding.top + bounding.height / 2
      })
      element.dispatchEvent(event)
    },
    done,
    selector
  )
}

/**
 * Mousedown on an element.

View on GitHub (pinned to 0f47de8499)

Solutions

  1. Verify the selector manually in the page's devtools with document.querySelector before using it in the script
  2. Wait for the element to exist before clicking, e.g. add .wait(selector) before .click(selector) in the Nightmare chain
  3. Correct typos or stale class/id names in the selector; re-inspect the live DOM since markup may have changed
  4. If the element is inside an iframe or shadow DOM, switch context to that frame before querying
  5. Increase the wait/delay so the page's JavaScript has finished rendering the element
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at lib/actions.js:110 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of segment-boneyard/nightmare@0f47de8499 (2026-09-02). Data as JSON: /api/errors/ce508b3697d4cd27. Report an issue: GitHub.