这是我的简单脚本,以查看图像是否存在。有没有办法可以使用选择器保存图像以查看它是否存在?这是我的代码:
var casper = require('casper').create();
casper.start('https://example.ws/', function() {
this.echo(this.getTitle());
});
casper.thenOpen('https://example.ws/login.html', function() {
this.echo(this.getTitle());
if (this.exists('img#cpt_img')) {
this.echo('the heading exists');
}
});
casper.run();
答案 0 :(得分:0)
您可以使用download()方法:
this.download(
this.getElementAttribute('img#cpt_img', 'src'),
"my_image.png"
);