2017-02-24 69 views
-1

基于从github上page我写了下面的代码示例:Nightmarejs代码评估/然后

// 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 

但是,如果我评论了。于是部分。代码的其余部分进行正常,浏览器出现并执行所有步骤。

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> 

我在做什么错?

+0

Downvoter:为什么downvote? – Ross

回答

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); 
    })