-
-
Save Kavan72/c5d3a00f230596700f2779f9e6f47ea4 to your computer and use it in GitHub Desktop.
Revisions
-
beatngu13 revised this gist
Jan 6, 2019 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // Taken from https://stackoverflow.com/a/47088726/3429133. function getAbsoluteXPath(element) { var comp, comps = []; var parent = null; @@ -51,7 +51,6 @@ function getAbsoluteXPath(element) { } } return xpath; } return getAbsoluteXPath(arguments[0]); -
beatngu13 revised this gist
Dec 11, 2018 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ function getAbsoluteXPath(element) { }; if (element instanceof Document) { return '/'; } for (; element && !(element instanceof Document); element = element.nodeType == Node.ATTRIBUTE_NODE ? element.ownerElement : element.parentNode) { @@ -45,12 +45,13 @@ function getAbsoluteXPath(element) { for (var i = comps.length - 1; i >= 0; i--) { comp = comps[i]; xpath += '/' + comp.name.toLowerCase(); if (comp.position !== null) { xpath += '[' + comp.position + ']'; } } return xpath; } return getAbsoluteXPath(arguments[0]); -
beatngu13 created this gist
Dec 11, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ // Taken from https://stackoverflow.com/a/43688599. function getAbsoluteXPath(element) { var comp, comps = []; var parent = null; var xpath = ''; var getPos = function(element) { var position = 1, curNode; if (element.nodeType == Node.ATTRIBUTE_NODE) { return null; } for (curNode = element.previousSibling; curNode; curNode = curNode.previousSibling) { if (curNode.nodeName == element.nodeName) { ++position; } } return position; }; if (element instanceof Document) { return xpath; } for (; element && !(element instanceof Document); element = element.nodeType == Node.ATTRIBUTE_NODE ? element.ownerElement : element.parentNode) { comp = comps[comps.length] = {}; switch (element.nodeType) { case Node.TEXT_NODE: comp.name = 'text()'; break; case Node.ATTRIBUTE_NODE: comp.name = '@' + element.nodeName; break; case Node.PROCESSING_INSTRUCTION_NODE: comp.name = 'processing-instruction()'; break; case Node.COMMENT_NODE: comp.name = 'comment()'; break; case Node.ELEMENT_NODE: comp.name = element.nodeName; break; } comp.position = getPos(element); } for (var i = comps.length - 1; i >= 0; i--) { comp = comps[i]; xpath += '/' + comp.name; if (comp.position !== null) { xpath += '[' + comp.position + ']'; } } return xpath; } return getAbsoluteXPath(arguments[0]);