diff --git a/lib/commands/screenshots.js b/lib/commands/screenshots.js index fd2685c40..ee0a1cba0 100644 --- a/lib/commands/screenshots.js +++ b/lib/commands/screenshots.js @@ -78,13 +78,19 @@ export default { el = util.unwrapElement(el); if (this.isWebContext()) { const atomsElement = this.getAtomsElement(el); - return await this.executeAtom('getElementScreenshot', [atomsElement]); + const {width, height} = await this.executeAtom('get_size', [atomsElement]); + if (!width || !height) { + throw new errors.UnableToCaptureScreen('Cannot take a screenshot of a zero-size element'); + } + const {x, y} = await this.executeAtom('get_top_left_coordinates', [atomsElement]); + return await (/** @type {import('appium-remote-debugger').RemoteDebugger} */ (this.remote)) + .captureScreenshot({rect: {x, y, width, height}}); } const data = await this.proxyCommand(`/element/${el}/screenshot`, 'GET'); if (!_.isString(data)) { - this.log.errorAndThrow( - `Unable to take a screenshot of the element ${el}. WDA returned '${JSON.stringify(data)}'`, + throw new errors.UnableToCaptureScreen( + `Unable to take an element screenshot. WDA returned: ${JSON.stringify(data)}`, ); } return data;