This package is a little piece of Google's Chromium DevTools project which modified to make it work on JSDOM.
The DOMPath is responsible for generating a selector given an element in a particular DOM hierarchy.
Its methods can be accessed via the following menu:
Open DevTools -> Navigate to Elements tab -> Right click on selected Element -> Copy
Installation
npm i -S chrome-dompath
DOMPath
Get selector, JS Path and XPath of a DOM element.
const DOMPath = ; // Nodeconst dom = '<root><a><b>T1</b><c>T2</c></a></root>'windowdocument;const element = dom; // Browserconst element = windowdocument; DOMPath;DOMPath;DOMPath;
API
DOMPath.fullQualifiedSelector(node: DOMNode | optimized: boolean)
Returns the full qualified selector (string) for the node supplied.
DOMPath;DOMPath;
DOMPath.jsPath(node: DOMNode | optimized: boolean)
Returns the JS path (string) for the node supplied.
DOMPath;DOMPath;
DOMPath.xPath(node: DOMNode | optimized: boolean)
Returns the xpath (string) for the node supplied.
DOMPath;DOMPath;