Get the XPath from an HTML element
npm install get-xpath



bash
npm i get-xpath
`
API
`typescript
function getXPath( element: HTMLElement, options?: Partial< Options > ): string;
`
Where options is an optional object containing:
| name | type | description |
|------------|---------|---------------------------------------|
| ignoreId | boolean | Do not take elements' ID into account |
Example:
`html
`
Usage
Notes:
- On Node or Deno, you have to provide a way to accessing or emulating the DOM.
You can use JSDOM (or any other library) for that.
- When using TypeScript, add the value "dom" to the property "lib"of your tsconfig.json. Otherwise you will probably get errors.
$3
Global:
`html
`
ESM:
`html
`
$3
`javascript
///
const getXPath = require('get-xpath');
console.log(
getXPath( document.getElementById( 'foo' ) )
);
`
$3
`typescript
///
import getXPath from 'https://unpkg.com/get-xpath/index.esm.js';
console.log(
getXPath( document.getElementById( 'foo' ) )
);
``