Skip to content

Commit 72f2c0f

Browse files
committed
[js] Add WebElement.takeScreenshot()
Fixes #958
1 parent 0ffd74f commit 72f2c0f

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v2.49.0-dev
2+
3+
* Added `WebElement#takeScreenshot()`.
4+
15
## v2.48.1
26

37
* FIXED: Adjusted how the control flow tracks promise callbacks to avoid a

javascript/node/selenium-webdriver/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "selenium-webdriver",
3-
"version": "2.48.1",
3+
"version": "2.49.0-dev",
44
"description": "The official WebDriver JavaScript bindings from the Selenium project",
55
"license": "Apache-2.0",
66
"keywords": [

javascript/webdriver/command.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ webdriver.CommandName = {
163163
ELEMENT_EQUALS: 'elementEquals',
164164

165165
SCREENSHOT: 'screenshot',
166+
TAKE_ELEMENT_SCREENSHOT: 'takeElementScreenshot',
166167
IMPLICITLY_WAIT: 'implicitlyWait',
167168
SET_SCRIPT_TIMEOUT: 'setScriptTimeout',
168169
SET_TIMEOUT: 'setTimeout',

javascript/webdriver/http/http.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ webdriver.http.Executor.COMMAND_MAP_ = (function() {
283283
get('/session/:sessionId/element/:id/css/:propertyName')).
284284
put(webdriver.CommandName.ELEMENT_EQUALS,
285285
get('/session/:sessionId/element/:id/equals/:other')).
286+
put(webdriver.CommandName.TAKE_ELEMENT_SCREENSHOT,
287+
get('/session/:sessionId/element/:id/screenshot')).
286288
put(webdriver.CommandName.SWITCH_TO_WINDOW,
287289
post('/session/:sessionId/window')).
288290
put(webdriver.CommandName.MAXIMIZE_WINDOW,

javascript/webdriver/webdriver.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,6 +2187,25 @@ webdriver.WebElement.prototype.isDisplayed = function() {
21872187
};
21882188

21892189

2190+
/**
2191+
* Take a screenshot of the visible region encompassed by this element's
2192+
* bounding rectangle.
2193+
*
2194+
* @param {boolean=} opt_scroll Optional argument that indicates whether the
2195+
* element should be scrolled into view before taking a screenshot. Defaults
2196+
* to false.
2197+
* @return {!webdriver.promise.Promise.<string>} A promise that will be
2198+
* resolved to the screenshot as a base-64 encoded PNG.
2199+
*/
2200+
webdriver.WebElement.prototype.takeScreenshot = function(opt_scroll) {
2201+
var scroll = !!opt_scroll;
2202+
return this.schedule_(
2203+
new webdriver.Command(webdriver.CommandName.TAKE_ELEMENT_SCREENSHOT)
2204+
.setParameter('scroll', scroll),
2205+
'WebElement.takeScreenshot(' + scroll + ')');
2206+
};
2207+
2208+
21902209
/**
21912210
* Schedules a command to retrieve the outer HTML of this element.
21922211
* @return {!webdriver.promise.Promise.<string>} A promise that will be

0 commit comments

Comments
 (0)