【问题标题】:Unable to click on a link with CasperJS无法单击带有 CasperJS 的链接
【发布时间】:2014-12-15 05:25:57
【问题描述】:

我正在尝试单击带有 CasperJS 的链接,但收到了这个奇怪的错误:[warning] [phantom] Loading resource failed with status=fail (HTTP 200): http://njit.edu/。这是我的代码:

// Creating a casper module instance
var casper = require('casper').create({
  verbose: true,
  logLevel: "debug"
});

var config = {
  url: 'http://telluswho2.herokuapp.com/',
};

casper.start(config.url);

casper.then(function() {
  console.log(this.getCurrentUrl());
  this.click('a.btn-lg:nth-child(3)');
  console.log(this.getTitle());
});

casper.run(function() {
  console.log(this.getTitle());
  this.exit();
});

以下是我尝试过的解决方案:

  • casperjs njit.js
  • casperjs njit.js --ssl-protocol=any
  • casperjs njit.js --ssl-protocol=tlsv1
  • casperjs njit.js --ignore-ssl-errors=yes
  • casperjs njit.js --ignore-ssl-errors=true
  • casperjs njit.js --ignore-ssl-errors=false
  • casperjs --ssl-protocol=any njit.js
  • casperjs --ssl-protocol=tlsv1 njit.js
  • casperjs --ignore-ssl=yes njit.js

所有这些可能的解决方案都会导致相同的错误。有什么想法吗?

【问题讨论】:

    标签: javascript testing ssl phantomjs casperjs


    【解决方案1】:

    根据我的快速测试,我相信按钮重定向到 http://njit.edu/ 而不是 http://www.njit.edu/,这就是您收到该错误的原因。

    然后有一个从http://njit.edu/http://www.njit.edu/ 的自动跳转,但PhantomJS 由于某种原因无法执行此重定向。

    【讨论】:

    • 您有什么建议可以说服 PhantomJS 打开页面/正确重定向?通过快速测试,SlimerJS 可以毫无问题地做到这一点。
    • 你可以使用onResourceReceived,这是我找到的一个例子:phantomjs redirect handling
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-26
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多