【问题标题】:How to call a function inside SpookyJS?如何在 SpookyJS 中调用函数?
【发布时间】:2014-07-15 22:23:48
【问题描述】:

我有一个名为clickMore的函数:

function clickMore(max, i){
   i = i || 0;
   if ((max == null || i < max) && this.visible(moreButton)) { // synchronous
      // asynchronous steps...
      this.thenClick(moreButton);  // sometimes the click is not properly dispatched
      this.echo('click');
      this.waitUntilVisible(loadingButton);
      this.waitUntilVisible(moreButton, null, function onTimeout(){
         // only placeholder so that the script doesn't "die" here if the end is reached
      });
      this.then(function(){

         //this.capture("business_"+i+".png");   //captures a screenshot of the page
         clickMore.call(this, max, i+1); // recursion
      });
   }
}

我想在这里从 spooky 调用该函数:

spooky.then(function(){
              clickMore.call(spooky);
          })

我查看了 Spooky 文档,知道我可能需要使用函数元组,但不确定如何实现。我该怎么做?

更新:

尝试使用 SpookyJS 文档中的函数元组,但没有成功:

spooky.then([{
   clickMore: clickMore
}, function(){
    clickMore.call(spooky);
}]);

【问题讨论】:

    标签: node.js phantomjs casperjs spookyjs


    【解决方案1】:

    传入spooky.then 的函数将在 Casper/PhantomJS JavaScript 环境中执行。他们无权访问 Spooky 的 Node.js JS 环境。

    spooky.then([{
       clickMore: clickMore
    }, function(){
        clickMore.call(spooky); // <- spooky is not defined here
    }]);
    

    请再看一下简介 wiki 页面上关于 JavaScript Environmentsthe fact that they are isolated 的内容。

    【讨论】:

    • 你实际上并没有回答这个问题。
    • 我确实做到了。提供的代码将不起作用。我解释了原因并指出了相关文档。
    • 好吧,根据问题中的更新,提供的代码不起作用。我了解您想指出错误是什么,但这并不能解决此问题。这更能说明问题的根源是什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多