单击按钮在CasperJS中不执行任何操作

时间:2016-06-05 16:09:35

标签: javascript click casperjs

我正在尝试自动化以下网站:http://www.1800flowers.com/orchids/purple-mini-101006?categoryId=400065010

我的代码是:

PreviewPaintRequested(QPrinter* printer)

结果我得到了

图片1:

  

enter image description here

图片2:

  

enter image description here

看看图片。你可以看到,我的代码使用2输入(Zipcode和位置类型)。然后点击show popup 。现在我的问题出现了。我不知道如何点击弹出框中的一个框(这个框有天数可供发货)

1 个答案:

答案 0 :(得分:1)

casper.mouse.click不是异步步骤函数,但casper.wait是异步的。这意味着它按此顺序执行:

this.evaluate(function(){ ... });
this.mouse.click('#calendarLink');
this.mouse.click('#DeliveryCalendarGPTDayCharges');
this.wait(20000);
this.wait(20000);

这可能不足以让第二次点击动态页面产生任何效果。您需要将这些点击分成不同的步骤:

this.evaluate(function(){ ... });
this.mouse.click('#calendarLink');
this.wait(20000, function(){
    this.mouse.click('#DeliveryCalendarGPTDayCharges');
});
this.wait(20000);

或更短:

this.evaluate(function(){ ... });
this.thenClick('#calendarLink')
    .wait(20000)
    .thenClick('#DeliveryCalendarGPTDayCharges')
    .wait(20000);

以下是具有适当wait*函数的更强大的示例:

this.thenClick('#calendarLink')
    .waitUntilVisible('#TB_window', function(){
        this.capture("1800_popup.png");
    }, null, 60000)
    .thenClick('#DeliveryCalendarGPTDayCharges')
    .waitWhileVisible('#TB_window', null, null, 60000);

此处'#TB_window'表示在第一次点击后打开并在第二次点击后关闭的模式。

相关问题