嘿,我正在尝试用噩梦截取一个元素的屏幕截图,而不是我想用一个函数从这个屏幕截图中提取文本,并在nightmare.type()
. 问题是当我使用nightmare.run()
屏幕截图不存在时出现错误。我怎样才能解决这个问题?这是我的代码:
var Nightmare = require('nightmare');
var Screenshot = require('nightmare-screenshot');
var nightmare = new Nightmare();
nightmare.goto('website');
//Takes screenshot of element
nightmare.use(Screenshot.screenshotSelector('screenshot' + i + '.png', 'img[id="yw0"]'));
nightmare.type('input[id=AuthForm_login]', username);
nightmare.type('input[id=AuthForm_password]', password);
nightmare.type('input[id=upload]', image.decodeFile('screenshot' + i + '.png', function(err, result){
//Returns Text from the Screenshot taken above!
return result.text;
}));
nightmare.run();
当我删除该行时:
nightmare.type('input[id=upload]', image.decodeFile('screenshot' + i + '.png', function(err, result){
//Returns Text from the Screenshot taken above!
return result.text;
}));
一切正常,我得到了一个截图。