added xpath basic helpers in clientutils
Showing
1 changed file
with
23 additions
and
0 deletions
... | @@ -340,6 +340,29 @@ | ... | @@ -340,6 +340,29 @@ |
340 | } | 340 | } |
341 | }; | 341 | }; |
342 | 342 | ||
343 | this.getElementByXPath = function getElementByXPath(expression) { | ||
344 | var a = document.evaluate(expression, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | ||
345 | if (a.snapshotLength > 0) { | ||
346 | return a.snapshotItem(0); | ||
347 | } | ||
348 | }; | ||
349 | |||
350 | this.getElementsByXPath = function getElementsByXPath(expression) { | ||
351 | var nodes = []; | ||
352 | var a = document.evaluate(expression, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | ||
353 | for (var i = 0; i < a.snapshotLength; i++) { | ||
354 | nodes.push(a.snapshotItem(i)); | ||
355 | } | ||
356 | return nodes; | ||
357 | }; | ||
358 | |||
359 | this.removeElementsByXPath = function removeElementsByXPath(expression) { | ||
360 | var a = document.evaluate(expression, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | ||
361 | for (var i = 0; i < a.snapshotLength; i++) { | ||
362 | a.snapshotItem(i).parentNode.removeChild(a.snapshotItem(i)); | ||
363 | } | ||
364 | }; | ||
365 | |||
343 | /** | 366 | /** |
344 | * Logs a message. Will format the message a way CasperJS will be able | 367 | * Logs a message. Will format the message a way CasperJS will be able |
345 | * to log phantomjs side. | 368 | * to log phantomjs side. | ... | ... |
-
Please register or sign in to post a comment