3

I copy pasted the example on Github:

app.js:

var Nightmare = require('nightmare');
var vo = require('vo');

vo(function* () {
  var nightmare = Nightmare({ show: true });
  var link = yield nightmare
    .goto('http://yahoo.com')
    .type('input[title="Search"]', 'github nightmare')
    .click('.searchsubmit')
    .wait('.ac-21th')
    .evaluate(function () {
      return document.getElementsByClassName('ac-21th')[0].href;
    });
  yield nightmare.end();
  return link;
})(function (err, result) {
  if (err) return console.log(err);
  console.log(result);
});

I did: npm install nightmare vo

Then node --harmony app.js but nothing outputs:

alex@alex-K43U:~/node/nightmarejs$ node --harmony app.js
alex@alex-K43U:~/node/nightmarejs$ 

No error messages whatsoever. What can be the problem?

(I'm running node v5.2.0 on Ubuntu.)

alexchenco
  • 53,565
  • 76
  • 241
  • 413

1 Answers1

1

Two part answer:

  1. Yahoo changed some of their internal naming around. Nightmare is (as the time of this answer) not great about excepting when actions on nonexistent elements fail, as with your example. The problem with Yahoo's names was reported in #490 and fixed in #491. From the fix:

    var Nightmare = require('nightmare');
    var nightmare = Nightmare({ show: true })
    
    nightmare
      .goto('http://yahoo.com')
      .type('input[title="Search"]', 'github nightmare')
      .click('#uh-search-button')
      .wait('#main')
      .evaluate(function () {
        return document.querySelector('#main .searchCenterMiddle li a').href
      })
      .end()
      .then(function (result) {
        console.log(result)
      });
    
  2. If you're running headlessly (eg, under Crouton or on DigitalOcean or with Docker), I would encourage you to have a look at #224. This also may produce the errant behavior you're seeing.

Ross
  • 2,448
  • 1
  • 21
  • 24