CasperJS后退导航无法正常工作

时间:2015-06-25 12:49:19

标签: javascript web-scraping phantomjs casperjs back

这是我的代码,后退导航无法正常工作,因为即使我等了2秒,屏幕截图也与之前相同。

phantom.casperPath = "/Users/manoj/apply_robots/casjs/casperjs";
phantom.injectJs(phantom.casperPath + "/bin/bootstrap.js");
phantom.injectJs("/Users/manoj/apply_robots/jquery/jquery-2.1.4.min.js");

var utils = require('utils');
var fs = require('fs');
var a;
var flag = 1;

var casper = require('casper').create();
casper.userAgent("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16");
var x = require('casper').selectXPath;

casper.start('https://piedmont.taleo.net/careersection/2/moresearch.ftl?lang=en',function(){

    casper.page.injectJs('/Users/manoj/apply_robots/jquery/jquery-2.1.4.min.js');
    this.echo(this.getTitle());
    this.evaluate(function() {
        document.querySelector('#requisitionListInterface\\.dropListSize').selectedIndex = 4;
        return true;
    });

    this.wait(3000,function(){});
});

casper.then(function(){
    this.thenClick(x('//*[@id="requisitionListInterface.pagerDivID4117.Next"]')).then(function() { 

        this.wait(2000,function(){
            this.capture("i1.png");
        });
    });
});

casper.then(function () {
    this.echo("inside back");
    this.back();
    this.wait(3000,function(){
        this.capture("i3.png");
    });
});

casper.then(function(){
    this.thenClick(x('//*[@id="requisitionListInterface.pagerDivID4117.Next"]')).then(function() { 
        this.wait(2000,function(){
            this.capture("i5.png");
        });
    });
});

1 个答案:

答案 0 :(得分:2)

有时需要执行两次back()调用才能使其正常工作:

casper.back().back();

我不知道为什么会这样,但它可能与重定向有关,这意味着当调用back()时,前一页面被加载只是重定向到页面的地方back()被召唤了。再次调用back()会在重定向页面之前加载页面。

相关问题