{"id":18576136,"url":"https://github.com/thiagodp/get-xpath","last_synced_at":"2025-04-10T08:31:04.258Z","repository":{"id":46687573,"uuid":"269250142","full_name":"thiagodp/get-xpath","owner":"thiagodp","description":"📑 Extract the XPath from an HTML element","archived":false,"fork":false,"pushed_at":"2025-01-31T17:32:42.000Z","size":319,"stargazers_count":37,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T19:01:43.619Z","etag":null,"topics":["browser","deno","html","javascript","node","typescript","xpath"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thiagodp.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-04T03:19:16.000Z","updated_at":"2025-03-19T13:45:26.000Z","dependencies_parsed_at":"2024-11-06T23:36:40.056Z","dependency_job_id":null,"html_url":"https://github.com/thiagodp/get-xpath","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fget-xpath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fget-xpath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fget-xpath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fget-xpath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thiagodp","download_url":"https://codeload.github.com/thiagodp/get-xpath/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248185324,"owners_count":21061496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","deno","html","javascript","node","typescript","xpath"],"created_at":"2024-11-06T23:23:44.920Z","updated_at":"2025-04-10T08:31:03.967Z","avatar_url":"https://github.com/thiagodp.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm (tag)](https://img.shields.io/npm/v/get-xpath?color=green\u0026label=NPM\u0026style=for-the-badge)](https://github.com/thiagodp/get-xpath/releases)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/thiagodp/get-xpath/test.yml?style=for-the-badge\u0026color=green)](https://github.com/thiagodp/get-xpath/actions)\n[![License](https://img.shields.io/npm/l/get-xpath.svg?style=for-the-badge\u0026color=green)](https://github.com/thiagodp/get-xpath/blob/master/LICENSE.txt)\n[![npm](https://img.shields.io/npm/dt/get-xpath?style=for-the-badge\u0026color=green)](https://www.npmjs.com/package/get-xpath)\n\n# get-xpath\n\n\u003e 📑 Extract the XPath of an HTML element\n\n- Works with browsers, [NodeJS](https://nodejs.org/) and [DenoJS](https://deno.land/) (JavaScript 5 and TypeScript)\n- No external dependencies\n- Unit-tested\n- Semantic Versioning\n\n## Install\n\n```bash\nnpm i get-xpath\n```\n\n## API\n\n```typescript\nfunction getXPath( element: HTMLElement, options?: Partial\u003c Options \u003e ): string;\n```\n\nWhere `options` is an optional object containing:\n\n| name       | type    | description                           |\n|------------|---------|---------------------------------------|\n| `ignoreId` | boolean | Do not take elements' ID into account |\n\nExample:\n\n```html\n\u003chtml\u003e\n    \u003cbody\u003e\n        \u003cdiv id=\"x\" \u003e\u003c/div\u003e\n        \u003cscript\u003e\n            const div = document.getElementById( 'x' );\n            const xpath1 = getXPath( div ); // returns '//*[@id=\"x\"]'\n            const xpath2 = getXPath( div, { ignoreId: true } ); // returns '/html/body/div'\n        \u003c/script\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n\n## Usage\n\n**Notes**:\n- On [Node](https://nodejs.org/) or [Deno](https://deno.land/), you have to provide a way to accessing or emulating the DOM.\nYou can use [JSDOM](https://github.com/jsdom/jsdom) (or any other library) for that.\n- When using TypeScript, add the value `\"dom\"` to the property `\"lib\"`of your `tsconfig.json`. Otherwise you will probably get errors.\n\n\n### Browser\n\nGlobal:\n```html\n\u003cscript crossorigin src=\"https://unpkg.com/get-xpath\" \u003e\n\u003cscript\u003e\nconsole.log(\n    getXPath( document.getElementById( 'foo' ) )\n);\n\u003c/script\u003e\n```\n\nESM:\n```html\n\u003cscript type=\"module\" \u003e\nimport getXPath from 'https://unpkg.com/get-xpath/index.esm.js';\nconsole.log(\n    getXPath( document.getElementById( 'foo' ) )\n);\n\u003c/script\u003e\n```\n\n### NodeJS\n\n```javascript\n/// \u003creference lib=\"dom\" /\u003e\nconst getXPath = require('get-xpath');\nconsole.log(\n    getXPath( document.getElementById( 'foo' ) )\n);\n```\n\n### Deno\n\n```typescript\n/// \u003creference lib=\"dom\" /\u003e\nimport getXPath from 'https://unpkg.com/get-xpath/index.esm.js';\nconsole.log(\n    getXPath( document.getElementById( 'foo' ) )\n);\n```\n\n## License\n\n[MIT](LICENSE.txt) © [Thiago Delgado Pinto](https://github.com/thiagodp)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Fget-xpath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthiagodp%2Fget-xpath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Fget-xpath/lists"}