下面的代码截取一个屏幕截图,并切断作为css选择器传递的某个元素。
const imageLib = require('imagelib/imageLib');
withoutElementScreenshot.prototype.command = function (selector, filename, cb) {
var self = this;
function execute(client, selector, filename, cb) {
client.element('css selector', selector, function (element) {
client.elementIdLocationInView(element.value.ELEMENT, function (location) {
client.elementIdSize(element.value.ELEMENT, function (size) {
client.takeScreenshot(filename, function () {
imageLib(filename).pngToData(function () {
for (var x = location.value.x; x < size.value.width + location.value.x; x++) {
for (var y = location.value.y; y < size.value.height + location.value.y; y++) {
this.setPixel(x, y, 255, 255, 255, 255);
}
}
this.toPng(filename, function () {
client.log('Screenshot without element would be saved into ' + filename);
cb();
});
});
});
});
});
});
}
如何传递选择器数组以将其全部切断?我无法遍历数组,因为takescreenshot函数位于回调之间。
暂无答案!
目前还没有任何答案,快来回答吧!