Nightmarejs 代码卡在 evaluate/then

Nightmarejs code stuck with evaluate/then

基于 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>

我做错了什么?

在他们的示例中,我总是在 .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);
  })