Skip to content

Instantly share code, notes, and snippets.

@navchandar
Created October 28, 2019 10:29
Show Gist options
  • Select an option

  • Save navchandar/c6d484dec29b838611f0e0bafab84e54 to your computer and use it in GitHub Desktop.

Select an option

Save navchandar/c6d484dec29b838611f0e0bafab84e54 to your computer and use it in GitHub Desktop.

Revisions

  1. navchandar created this gist Oct 28, 2019.
    12 changes: 12 additions & 0 deletions getElementsByXPath.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    function getElementsByXPath(xpath, parent) {
    let results=[];
    let query = document.evaluate(xpath, parent||document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    for(let i = 0,length = query.snapshotLength;i < length;++i){
    results.push(query.snapshotItem(i));
    }
    return results
    };

    items = getElementsByXPath("//*");
    items.length