2017-02-24 91 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); 
    })