【发布时间】:2016-06-05 16:09:35
【问题描述】:
我正在尝试自动化以下站点:http://www.1800flowers.com/orchids/purple-mini-101006?categoryId=400065010
我的代码是:
var casper = require("casper").create();
var mouse = require("mouse").create(casper);
var casper = require('casper').create({
verbose: true,
//logLevel: 'debug', // debug, info, warning, error
clientScripts: ["includes/jquery.min.js"],
pageSettings:{
loadImages: false,
loadPlugins: false,
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586'
}
}
);
var fs = require('fs');
casper.start().thenOpen("http://www.1800flowers.com/orchids/purple-mini-101006?categoryId=400065010", function(){
console.log("Access Site 1800.Com");
this.wait(10000);
});
casper.then(function(){
this.capture("1800_1.png");
});
casper.then(function(){
this.evaluate(function(){
$('#zipCode').attr('value', '12345');
$('#locationCode').attr('value', 'Residence');
//document.querySelector('select[id="locationCode"]').focus();
});
this.mouse.click('#calendarLink');
this.wait(20000);
this.mouse.click('#DeliveryCalendarGPTDayCharges');
this.wait(20000);
//this.sendEvent('keypress', this.page.event.key.Down);
});
casper.then(function(){
this.capture("1800_2.png");
console.log(this.getCurrentUrl());
});
casper.run();
我得到的结果
图一:
图二:
看图片。您可以看到,我的代码使用 2 个输入(邮政编码和位置类型)。它点击显示弹出窗口。现在我的问题出现了。我不知道要让它点击弹出窗口中的一个框(这个框有几天可以发货)
【问题讨论】:
标签: javascript click casperjs