梦魇js无法读取null的属性'焦点'

时间:2017-03-09 20:02:11

标签: javascript nightmare

我不能让梦魇js工作:

我的代码

var Nightmare = require('nightmare'),
  nightmare = Nightmare({
    show: true
  });

console.log('fer');

nightmare
  .goto('http://www.google.com')
  .type('input[title="Search"]', 'github nightmare')
  .click('name[btnK]')
  .wait('#main')
  .evaluate(function() {
    console.log('xxxxxx');
    var x = document.querySelector('.srg .g');
    var item = x.querySelector("h3").textContent;
    console.log(item);
  })
  .end() // end the Nightmare instance along with the Electron instance it wraps
  .then(function(result) {
    console.log(result);
  });

错误

set DEBUG=nightmare & node src\crawler\google-spider.js
  nightmare queuing process start +0ms
fer
  nightmare queueing action "goto" for http://www.google.com +10ms
  nightmare queueing action "type" +23ms
  nightmare queueing action "click" +0ms
  nightmare queueing action "wait" +1ms
  nightmare queueing action "evaluate" +0ms
  nightmare running +1ms
  nightmare electron child process exited with code 0: success! +5s
(node:7912) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Cannot read property 'focus' of null

有没有办法显示它失败的地方,或者什么是属性null

噩梦电子子进程退出代码0:成功! + 5S     (node:7912)UnhandledPromiseRejectionWarning:未处理的promise promise(拒绝id:1):无法读取null的属性'focus'

3 个答案:

答案 0 :(得分:0)

尝试设置所有噩梦消息:

DEBUG =恶梦*

答案 1 :(得分:0)

type调用会生成错误,我知道因为只有type调用焦点属性。

此外,console.log('xxxxxx');将不会显示,因为评估中的代码在Electron实例上运行。

答案 2 :(得分:0)

如果网页未完全加载,则可能发生这种情况。尝试在“ .goto”之后添加“ .wait(1000)”。