Nightmarejs代码坚持评估/然后

时间:2017-02-24 18:39:56

标签: node.js nightmare

基于github page的示例,我编写了以下代码:

// There is some stuff before this that loads the page and do a few clicks but it's not relative to the problem

var selector = 'ContentPlaceHolder1_dtlA_lnkB_0';
nightmare
  .evaluate(function (selector) {
    return document.querySelector(selector).innerText;
   }, selector)
  .then(function(text) {
    console.log(text);
  })

但是,当我运行代码时,它会因没有输出而卡住。浏览器甚至没有出现。

DEBUG=nightmare node checkjobs.js    
nightmare queuing process start +0ms
nightmare queueing action "goto" for http://xxxxxxxxx/Login.aspx +3ms
nightmare queueing action "type" +2ms
nightmare queueing action "type" +0ms
nightmare queueing action "click" +0ms
nightmare queueing action "wait" +0ms
nightmare queueing action "click" +0ms
nightmare queueing action "wait" +0ms
nightmare queueing action "click" +0ms
nightmare queueing action "evaluate" +0ms
nightmare running +1ms
nightmare running +16ms

但是,如果我评论.then部分。其余的代码很好,浏览器出现并完成所有步骤。

HTML看起来像这样:

<a id="CContentPlaceHolder1_dtlA_lnkB_0" class="LinkButonDark" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$dtlA$ctl00$lnkB','')" style="color: #97c1e2; text-transform: capitalize;"><b>SOME TEXT I NEED TO CAPTURE</b></a>

我做错了什么?

1 个答案:

答案 0 :(得分:1)

在他们的示例中,我始终在.then()之前看到.end()

试试这个:

var selector = 'ContentPlaceHolder1_dtlA_lnkB_0';
nightmare
  .evaluate(function (selector) {
    return document.querySelector(selector).innerText;
   }, selector)
  .end()
  .then(function(text) {
    console.log(text);
  })
相关问题