簡體   English   中英

使用截圖的功能的夢魘類型結果

[英]Nightmare type result of function which is using taken screenshot

嘿,我試圖用噩夢拍攝一個元素的截圖,而不是我想用一個函數從這個截圖中提取文本,並在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;
    }));

一切正常,我得到一個截圖。

當夢魘使用Phantomjs你可以這樣做,雖然我發現這下面應該有所幫助。

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

NightmareJS截圖回調

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM