Javascript 使用CasperJS使用更新的数据进行刮链选择

Javascript 使用CasperJS使用更新的数据进行刮链选择,javascript,phantomjs,html-select,casperjs,Javascript,Phantomjs,Html Select,Casperjs,有两个ID为的选择。第二个选择框数据将根据您在第一个选择框上选择的内容进行链接。换句话说,如果您在第二个选择框中选择BMW,则应显示316318320。。。你说得对 第一个select具有侦听器 ('#brand').change(function(){ call ajax and fill the data for the second select box } 最后我想做的是为所有品牌的车型提供所有选项:- 到目前为止,我得到的是: var casper = require('ca

有两个ID为的选择。第二个选择框数据将根据您在第一个选择框上选择的内容进行链接。换句话说,如果您在第二个选择框中选择BMW,则应显示316318320。。。你说得对

第一个select具有侦听器

('#brand').change(function(){
    call ajax and fill the data for the second select box
}
最后我想做的是为所有品牌的车型提供所有选项:-

到目前为止,我得到的是:

var casper = require('casper').create({
    loadImages:false,
    verbose: true,
    logLevel: 'debug',
    clientScripts: ["includes/jquery.min.js"]
});

casper.userAgent('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36');

casper.on('remote.message', function(msg) {
    this.echo('remote message caught: ' + msg);
});

casper.on( 'page.error', function (msg, trace) {
    this.echo( 'Error: ' + msg, 'ERROR' );
});

casper.start('http://www.mywebsite.kitchen/');

casper.then(function(){
    this.evaluate(function(valueOptionSelect){
        $('#brand').val(6).trigger('change');
    },optionFirstSelect);

    this.waitFor(function check() {
        return this.evaluate(function(casper) {
            var len = $('#model1 option').length;
            console.log('length of options is ->', len);
            return $('#model1 option').length > 1;
        });
    }, function then() {

       //well i still haven't reach that point

    }, function timeOut(){
        casper.echo(arguments)
    });
});

casper.run(function() {
    //finish execution script
    this.exit();
});
现在,我得到的控制台日志是:

//编辑-长度为1而不是0

选项长度为1


当我执行$'brand'.val6.触发'change';$'model1选项'.length在我的浏览器控制台中,我得到了正确的结果。

您可能是指$'model1选项'.length>0;在check函数中。您收到的选项长度为0的消息有多少?您应该将this.echo添加到waitFor-then-callback和timeout-callback中,以便区分它们。除此之外,它看起来是正确的。model select中有一个默认的空选项,这就是为什么我需要多于1的选项。我看到这个选项的消息长度是0~30-50倍。我确实尝试了与setTimeoutfunction{}的copule,但它没有改变任何东西。你能给我举个简单的例子说明你所说的设置超时是什么意思吗。Thanksettimeout不应该与casperjs一起使用,因为这样会丢失控制流。您可以添加resource.error、resource.received和resource.requested以查看请求是否完成。可能在运行casperjs时使用-web security=false命令行标志。好的,据我所知,我添加了:casper.on'resource.error',function msg,trace{this.echo'这是一个RESORCE错误:'+msg',error';};casper.on'resource.received',函数msg,跟踪{this.echo'A resource has received';};casper.on'resource.requested',函数msg,跟踪{this.echo'已请求资源';};然后我运行undend casperjs server.js-web security=false我得到的是30-40个已请求的资源已请求的资源已接收的资源已请求的资源