如何将图像保存到临时文件以便以后使用?

时间:2014-03-11 20:35:47

标签: css casperjs

这是我的简单脚本,以查看图像是否存在。有没有办法可以使用选择器保存图像以查看它是否存在?这是我的代码:

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();

1 个答案:

答案 0 :(得分:0)

您可以使用download()方法:

this.download(
    this.getElementAttribute('img#cpt_img', 'src'),
    "my_image.png"
);