Javascript 使用截图的函数的噩梦类型结果

Javascript 使用截图的函数的噩梦类型结果,javascript,node.js,nightmare,Javascript,Node.js,Nightmare,嘿,我正在尝试拍摄一个带有梦魇的元素的屏幕截图,然后我想用一个函数从这个屏幕截图中提取文本,并在梦魇.type()中使用结果。问题是当我使用dream.run()时,我得到一个错误,屏幕截图不存在。我怎样才能解决这个问题?这是我的代码: var Nightmare = require('nightmare'); var Screenshot = require('nightmare-screenshot'); var nightmare = new Nightmare(); nightmare

嘿,我正在尝试拍摄一个带有梦魇的元素的屏幕截图,然后我想用一个函数从这个屏幕截图中提取文本,并在
梦魇.type()
中使用结果。问题是当我使用
dream.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;
    }));

一切都很好,我得到了一张截图。

因为噩梦使用了幻影,所以你可以这样做,尽管我在下面发现了这一点,应该会有所帮助

归功于@fernandopasik,他说:

我找到了一种方法,使用“use”方法执行插件

nightmare = new Nightmare(); urls.forEach(function (url) {
    nightmare.goto(url).screenshot(path).use(function () {
        console.log('finished one');
    }); });

nightmare.run(function () {
    console.log('finished all'); });

我不能使用它,因为当
噩梦.run()时,它会立即抛出错误,我需要先处理图像,然后在同一个噩梦中重新使用它