Код Nightmarejs застрял с оценкой / затем
На основе примера со страницы github я написал следующий код:
// 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 ответ
Решение
В их примере я всегда вижу .end() перед .then()
,
Попробуй это:
var selector = 'ContentPlaceHolder1_dtlA_lnkB_0';
nightmare
.evaluate(function (selector) {
return document.querySelector(selector).innerText;
}, selector)
.end()
.then(function(text) {
console.log(text);
})