CasperJS登录Ghost CMS并截取屏幕截图

时间:2018-06-19 05:34:56

标签: javascript casperjs

到目前为止,这是我的剧本。

我还在你们和gals的代码下面发布了输出。

当它运行时它不会停止并且永远不会返回屏幕截图只是挂起而没有错误或任何东西。

var casper = require('casper').create({
  verbose: true,
  logLevel: 'debug',
  pageSettings: {
    loadImages: true,
    loadPlugins: true,
    userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0'
  }
});

casper.start('https://dilionsmith.me/ghost/#/signin', function() {
  this.waitForSelector('form[method="post"]');
});

casper.then(function() {
  console.log("page loaded");
  this.fill('form[method="post"]', {
    identification: 'email',
    password: 'pass'
  }, true);
});

casper.then(function() {
  casper.capture('after.png');
});

casper.run();

输出:

[info] [phantom] Starting...
[info] [phantom] Running suite: 4 steps
[debug] [phantom] opening url: https://dilionsmith.me/ghost/#/signin, HTTP GET
[debug] [phantom] Navigation requested: url=https://dilionsmith.me/ghost/#/signin, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://dilionsmith.me/ghost/#/signin"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/4 https://dilionsmith.me/ghost/#/signin (HTTP 200)
[info] [phantom] Step anonymous 2/4: done in 578ms.
[info] [phantom] Step _step 3/5 https://dilionsmith.me/ghost/#/signin (HTTP 200)
[info] [phantom] Step _step 3/5: done in 598ms.
[debug] [phantom] Navigation requested: url=https://dilionsmith.me/ghost/#/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://dilionsmith.me/ghost/#/"
[debug] [phantom] url changed to "https://dilionsmith.me/ghost/#/"

1 个答案:

答案 0 :(得分:0)

问题是您没有在“:”上输入输入名称:

ionic cordova platform add android@6.3.0

应为:

casper.then(function() {
  console.log("page loaded");
  this.fill('form[method="post"]', {
    identification: 'email',
    password: 'pass'
  }, true);
});

希望有帮助。