Commit fe0400c8 fe0400c851477def059d26e6b4eb74691dca6aba by Nicolas Perriault

added xpath basic helpers in clientutils

1 parent 4de595af
...@@ -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.
......