CasperJS cannot clear AJAX webpage

I'm trying to clean up http://www.snapdeal.com/offers/deal-of-the-day

which loads JSON data using the AJAX call on the page below:

json_url = http://www.snapdeal.com/json/getProductById?*

      

The code block I am using is below, I get the log message Waiting for AJAX request:

but not Waiting for AJAX request:

, instead of waitForResource

times

casper.options.onResourceRequested = function (casper, requestData){
    // loop through our AJAX urls
    // create list of AJAX urls to track
    var ajaxUrls = [json_url];

    ajaxUrls.every(function(ajaxUrl){
        // does this request match an AJAX url
        if(requestData.url.indexOf(ajaxUrl) !== -1){
            // it matches, so we'll wait for it to return (with 10s timeout)
            //console.log("Waiting for AJAX request: " + requestData.url);
            // print_object(requestData);
            casper.waitForResource(requestData.url, function(){
                console.log("AJAX request returned: " + requestData.url);
            }, function(){
                console.log("AJAX request didn't return after wait period: " + requestData.url)
            }, 10000);
        }
    });
}

      

To continue debugging, I logged events and the resource at url json_url

was successfully received, but not sure why the waitForResource

time is out.

casper.on('resource.received', function(resource) {
    if (resource.url.indexOf('http://www.snapdeal.com/json/getProductById') != -1){
        casper.echo('resource.received: ' + resource.url);

    }

});

      

Log after launch:

Waiting for AJAX request: http://www.snapdeal.com/json/getProductById?pogIds=671556289429,649272180,60998,685755068805,677649317861,1239888775,661402031482,636966047361,1775140628,1822452791,439536 ,Range,2042952975,1472100667,899358889,643129681532,668235859588,&lang=en

resource.received: http://www.snapdeal.com/json/getProductById?pogIds=671556289429,649272180,60998,685755068805,677649317861,1239888775,661402031482,636966047361,1775140628,1822452791,439536,Range, 2042952975,1472100667,899358889,643129681532,668235859588,&lang=en

resource.received: http://www.snapdeal.com/json/getProductById?pogIds=671556289429,649272180,60998,685755068805,677649317861,1239888775,661402031482,636966047361,1775140628,1822452791,439536,Range, 2042952975,1472100667,899358889,643129681532,668235859588,&lang=en

AJAX request didn't return after wait period: http://www.snapdeal.com/json/getProductById?pogIds=671556289429,649272180,60998,685755068805,677649317861,1239888775,661402031482,636966047361,17751406 28,1822452791,439536,Range,2042952975,1472100667,899358889,643129681532,668235859588,&lang=en Got page No Offeres Found thestartin: ~/Appli

      

+3


source to share


1 answer


What you need:

casper.waitForSelector()

      



or

casper.waitFor(function() {
    // test here something that return true when the page is loaded
})

      

0


source







All Articles