javascript - 使用所拍摄屏幕截图的功能的 Nightmare 类型结果

标签 javascript node.js nightmare

嘿,我正在尝试制作一个 Nightmare 般的元素的屏幕截图,然后我想使用功能从此屏幕截图中提取文本,并在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;
    }));

一切正常,我得到了屏幕截图。

最佳答案

当 Nightmare 使用Phantomjs时,您可以那样做,尽管我发现下面的内容应该有所帮助。

归功于@fernandopasik,他说:

I found a way to do this, with the "use" method for executing plugins.

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'); });


NightmareJS screenshot callback

关于javascript - 使用所拍摄屏幕截图的功能的 Nightmare 类型结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28587266/

相关文章:

javascript - 如何让玩家锁定其半径内的一个敌人?

javascript - JS - undefined object (但该对象已定义)

javascript - chrome新窗口访问文档

javascript - 过滤 $lookup 的结果

javascript - Nightmare - 文件来自哪里?

nightmare - Nightmare 如何上传图像文件?

javascript - 替换并着色 console.log() 中的参数

node.js - Node soap,使用受密码保护的 WSDL

node.js - 2018 年,谷歌的一位技术主管表示,他们正在 64 位系统上的 V8 中解决 "support buffers way beyond 4GiB"。那发生了吗?

javascript - 无法在特定站点中使用我的 NightmareJS v2 脚本登录。我收到 Oracle 错误