【问题标题】:NightmareJs goto after evaluateNightmareJs 在评估后转到
【发布时间】:2017-10-05 13:29:11
【问题描述】:

我并没有真正得到 nightmarejs,所以它可能真的很简单。
我的问题是为什么应用程序卡在 Facebook 网址上并且没有转到 Google?

 var Nightmare = require('nightmare');
 var nightmare = Nightmare({ show: true });

 nightmare
   .goto('https://facebook.com')
   .evaluate(function () {
       return document.title;
     }
   )
   .then(function(result){
     console.log(result)
     nightmare.goto('https://google.com')
   })

【问题讨论】:

    标签: javascript nightmare


    【解决方案1】:

    以下行返回一个promise,您首先将promise 解析为数据。只需在噩梦承诺链中添加then()。

        nightmare
         .goto('https://google.com')
         .then(function(){
            console.log("I'm done")
         })
    

    这是具有更好链的完整代码。

     var Nightmare = require('nightmare');
     var nightmare = Nightmare({ show: true });
    
     nightmare
       .goto('https://facebook.com')
       .evaluate(function () {
           return document.title;
         }
       )
       .then(function(result){
         console.log(result)
         return nightmare.goto('https://google.com')
       })
       .then(function(){
         console.log("I am on google")
       })
    

    这是结果,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-28
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 1970-01-01
      • 2012-03-10
      • 2012-02-03
      • 1970-01-01
      相关资源
      最近更新 更多