Casperjs并且无法使用captureSelector保存屏幕截图

时间:2013-11-19 11:56:24

标签: phantomjs casperjs

我有这样的代码:

  casper.thenOpen(url, function() {
    this.echo('Opening at ' + width);
    //give some time for the page to load
    casper.waitFor(function check() {
      return this.evaluate(function() {
        return document.querySelectorAll('#browse-packshots').length > 0;
      });
    }, function then() {
      //set the viewport to the desired height and width
      this.viewport(width, height);
      //Set up two vars, one for the fullpage save, one for the actual viewport save
      var FPfilename = saveDir + '/fullpage-' + width + ".png",
          ACfilename = saveDir + '/' + width + '-' + height + ".png";

      //Capture selector captures the whole body
      this.captureSelector(FPfilename, 'body');
      //capture snaps a defined selection of the page
      this.capture(ACfilename,{top: 0,left: 0,width: width, height: height});
      this.echo('snapshot taken');
    },function timeout() {
      this.echo("Too long . No screenshot taken").exit();
    },10000);
  })

Mac上的Casper版本为1.0.4。当我想使用captureSelector时,我正在

[error] [phantom] Failed to save screenshot to fullpage-1440.png;
                  please check permissions...

通过捕获没有问题。我的事件尝试使用sudo但没有效果。

1 个答案:

答案 0 :(得分:1)

我想我找到了答案。我在代码中更改了一个东西:

this.captureSelector(FPfilename, 'html');

不知道为什么它不起作用。