These are chat archives for rosshinkley/nightmare

15th
Jan 2017
Nina Breznik
@ninabreznik
Jan 15 2017 09:50
Hey, I have a problem when I want to click a button that is not an a tag.
I get this error
Search failed: Cannot read property 'href' of null
The code is this
var nightmare = require('nightmare')

var meta = require('_meta')
var get = require('_get')

var URL = get.url(__filename)
var NAME = get.name(URL)

module.exports = execute

function execute (opts, done) {
  if (typeof done !== 'function') return
  opts = opts || { show: false }
  opts.show = true
  nightmare(opts)
    .goto('https://www.peopleperhour.com/freelance-jobs')
    .click('.hidden-md a')
    .type('#keyword', 'javascript')
    .click('.js-submit-search')
    .evaluate(function () {
      return document.querySelector('#zero_click_wrapper .c-info__title a').href;
    })
    .end()
    .then(function (result) {
      console.log(result);
    })
    .catch(function (error) {
      console.error('Search failed:', error);
    });
}