casper.click() 不像真正的网络

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

我正在尝试自学 casperjs。

我遇到了一个不知道如何解决的问题。我正在尝试执行以下操作:

单击搜索框,会出现一个弹出窗口。但是,当我通过 casperjs 执行时,drop 并没有出现。

我需要在此字段中输入一个城市的值,然后单击出现的下拉菜单。

我觉得应该是没有发布必要的jquery事件的事情

我的代码:

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();

我将不胜感激,我已经尝试了我所知道的一切。

谢谢

我不确定你在期待什么。我会做的是使用 jquery 来模仿这种行为。 我看过网站。当您在巴塞罗那输入字段和键时,它会调用网络服务: http://suggest.vibbo.com/regionSuggest?callback=jQuery111106577302796537023_1474408404858&location=barcelona&_=1474408404866

所以我要做的是: 1) 通过调用网络服务收集建议:

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

(这里是 madri,取第一个结果: {"label":"Madridanos","regionID":“49”,"areaID":“”,"municipalityID":“49103”}

2) 用这个值填充字段:

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

3) 最终按下 Buscar 按钮:

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

是您要找的吗?