Search code examples
javascriptjqueryweb-scrapingphantomjscasperjs

casper.click() does not act like the real web


I 'm trying to learn as an autodidact casperjs .

I have encountered a problem that I do not know how to fix. I'm trying to do the following:

enter image description here

By clicking on the search box , a pop-up appears. However, when I do it by casperjs the drop does not appear.

What I need is to enter in this field the value of a city and click on the drop-down that appears.

I think it should be a matter that does not release the necessary jquery events.

My code:

var casper = require('casper').create({
    verbose: true,
    logLevel: "debug",
    waitTimeout: 10000,
    viewportSize: {
        width: 1024,
        height: 760
    }
});

/*
 * PARAMETERS
 */
var listItems = [];
var location = casper.cli.args[0];

casper.start('http://www.vibbo.com/pisos-y-casas-barcelona-capital/', function() {

    this.echo(this.getHTML('title'));
    this.captureSelector('vibbo-1.png', 'html');
    casper.click('#sb_location');
    this.captureSelector('vibbo-2.png', 'html');
});

casper.waitUntilVisible('#ui-id-1', function() {

    
    casper.sendKeys('#sb_location', 'Valencia');
    
    this.wait(1000, function() {
       this.captureSelector('vibbo-3.png', 'html');
    });
    
    this.echo(listItems);
});

casper.run();

I would appreciate help and I've tried everything I knew .

Thank you


Solution

  • I am not sure what you are expecting. What I would do, is to use jquery to mimic the behavior. I have looked at the web site. When you enter the field and keys in barcelona, it calls a webservice : http://suggest.vibbo.com/regionSuggest?callback=jQuery111106577302796537023_1474408404858&location=barcelona&_=1474408404866

    So what I would do is the following : 1) collect the suggestions by calling the Web Service :

    jQuery.getJSON("http://suggest.vibbo.com/regionSuggest?callback=jQuery111106577302796537023_1474408404858&location=mardid&_=1474408404866")
    

    (Here with madri, take the first result : {"label" : "Madridanos", "regionID":"49", "areaID": "", "municipalityID" : "49103"}

    2) Fill the field with this value :

    casper.evaluate(function(){
        $('#sb_location').val('Madridanos')
    }
    

    3) Eventually hit the Buscar button :

    $('button#sb_searchbutton').click();
    

    Is it what you were looking for ?