如何在 casperjs 中维护会话?

How to maintain session in casperjs?

在 CasperJS 中,使用 casper.thenOpen()

时如何保持会话

例如:

var casper = require('casper').create();

casper.start('http://chaseonline.com/', function() {
    this.echo(this.getTitle());
    this.evaluate(function() {
       document.getElementById("userid").value = "a@b.com";
       document.getElementById("password").value = "asdf";

     });
    this.click("#btnSubmit");
});

casper.thenOpen('http://chaseonline.com/section/1/module/2/abc.jsp', function() {
  // now this page never loads because the page requires a logged in session 
  // but casperjs doesn't appear to automatically propagate the session
  this.echo(this.getTitle());
});

casper.run();

会话在您的示例中仍处于打开状态。可能您没有正确登录。
可能是如果它一步一步工作(似乎我看到的网站不是你的例子中的那个,没有登录):

var casper = require('casper').create();
var x = require('casper').selectXPath;

casper.start('http://youraddess.com/', function() {
  casper.then(function() {
    casper.waitForSelector(x("xpath_selector"));
  });
  var data = {};
  casper.then(function() {
    data["//input[@id='userid']"] = "a@b.com";
    data["//input[@id='password']"] = "asdf";
    casper.fillXPath(x("//form[]"), data, false);
  });
  casper.then(function() {
    casper.click(x("//button[@id='btnSubmit']"));
  });
  casper.then(function() {
    casper.waitWhileSelector(x("xpath_selector"));
  });
});
casper.thenOpen('http://chaseonline.com/section/1/module/2/abc.jsp', function() {
  // now this page never loads because the page requires a logged in session 
  // but casperjs doesn't appear to automatically propagate the session
  casper.then(function() {
    casper.echo(this.getTitle());
    casper.capture('test.png');
  });
});

casper.run();

会话一直到 运行() 始终相同。有可能开新的,但是很难。