added Casper#captureSelector() to capture and render a DOM element by its CSS3 selector
Showing
1 changed file
with
20 additions
and
0 deletions
... | @@ -117,6 +117,23 @@ | ... | @@ -117,6 +117,23 @@ |
117 | }, | 117 | }, |
118 | 118 | ||
119 | /** | 119 | /** |
120 | * Captures the page area containing the provided selector. | ||
121 | * | ||
122 | * @param String targetFile Target destination file path. | ||
123 | * @param String selector CSS3 selector | ||
124 | * @return Casper | ||
125 | */ | ||
126 | captureSelector: function(targetFile, selector) { | ||
127 | return this.capture(targetFile, self.evaluate(function() { | ||
128 | try { | ||
129 | return document.querySelector(selector).getBoundingClientRect(); | ||
130 | } catch (e) { | ||
131 | console.log('unable to fetch bounds for element ' + selector); | ||
132 | } | ||
133 | })); | ||
134 | }, | ||
135 | |||
136 | /** | ||
120 | * Checks for any further navigation step to process. | 137 | * Checks for any further navigation step to process. |
121 | * | 138 | * |
122 | * @param Casper self A self reference | 139 | * @param Casper self A self reference |
... | @@ -338,6 +355,9 @@ | ... | @@ -338,6 +355,9 @@ |
338 | * @return Casper | 355 | * @return Casper |
339 | */ | 356 | */ |
340 | start: function(location, then) { | 357 | start: function(location, then) { |
358 | if (this.started) { | ||
359 | this.log("start failed: Casper has already started!", "error"); | ||
360 | } | ||
341 | this.log('Starting…', "info"); | 361 | this.log('Starting…', "info"); |
342 | this.startTime = new Date().getTime(); | 362 | this.startTime = new Date().getTime(); |
343 | this.steps = []; | 363 | this.steps = []; | ... | ... |
-
Please register or sign in to post a comment