casperjs对表单使用waittentivisible

casperjs using waituntilvisible for form

本文关键字:waittentivisible 表单 casperjs      更新时间:2023-09-26

我使用Casperjs进行任务自动化,并且必须填写一张包含提货日期、交车日期和提货地点的表格。

填写提货日期和还车日期很好。(我可以用屏幕截图查看)。

当您开始填写指定的提货地点时,会根据您键入的内容生成一个选项列表。此列表显示在:

 <ul class="ct-autocomplete ct-ui-base" id="ui-id-1" ....></ul>

所以我尝试使用:this.waitUntilVisible('u#ui-id-1',function()但我得到以下错误:

[warning] [phantom] Casper.waitFor() timeout
FAIL "u#ui-id-1" never appeared in 10000ms
#    type: uncaughtError
#    error: "u#ui-id-1" never appeared in 10000ms
#    stack: not provided

谢谢你的帮助洛伦佐

casper.options.waitTimeout = 10000;
// print out all the messages in the headless browser context
casper.on('remote.message', function(msg) {
    this.echo('remote message caught: ' + msg);
});
// print out all the messages in the headless browser context
casper.on("page.error", function(msg, trace) {
    this.echo("Page Error: " + msg, "ERROR");
});
casper.start(url, function() {
   console.log("page loaded");
});
casper.then(function() {
  this.waitForResource(this.getCurrentUrl(),function() {
    //Filling Pick Up Date    
   this.click('input#ct_s1_pickup_date');
   this.fill('form#ct_s1_frm_search', {
    'ct_pickup_date':   '05/04/2015'
   },false);
   //Filling Drop Off Date
   this.click('input#ct_s1_dropoff_date');
   this.fill('form#ct_s1_frm_search', {
    'ct_dropoff_date':   '15/04/2015'
   },false);
   this.capture('screenshot step1.png');
  },function() {
  },5000);
});
casper.then(function() {
    //Filling Pick Up Location
   this.click('input#ct_s1_pickup_loc');
   this.fill('form#ct_s1_frm_search', { 
        'ct_pickup_loc':    'Barcelone'
    },false);
   this.echo(this.getHTML('ul#ui-id-1', true));
   this.waitUntilVisible('u#ui-id-1', function() {
    this.capture('screenshot step3.png');
    });
});
casper.evaluate(function(){
 });
casper.run(function() {
    this.exit();
});

"fill"看起来不会触发任何东西,但"sendkeys"会触发。

所以我替换了:

this.fill('form#ct_s1_frm_search', { 
        'ct_pickup_loc':    'Barcelone'
    },false);

发件人:

casper.then(function() { this.sendKeys('input#ct_s1_pickup_loc','Barcelone',{reset: true,keepFocus: true}); });

然后根据"巴塞罗那"的要求建立了一个选择列表。

相关文章:
  • 没有找到相关文章