Skip to content

crazyurus/compute-xpath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compute xPath

publish BSD-3-Clause License npm npm dependents npm downloads

This is a library that generates xPath based on DOM elements. The implementation is extracted from Chrome DevTools Frontend

Introduction

You can generate xPath based on DOM elements. For example:

import { computeXPath } from 'compute-xpath';

const xPath = computeXPath(element)[0];

If you need to query the corresponding element or text based on xPath, you can call the browser API document.evalute. For example:

const result = document.evaluate(xPath, document.documentElement);
const element = result.iterateNext();

Parameters

  • node: The node to compute
  • optimized: Whether to optimize the XPath for the node. Does not imply the XPath is shorter; implies the XPath will be highly-scoped to the node.

License

BSD-3-Clause

About

A library to generate xPath based on DOM elements

Topics

Resources

License

Stars

Watchers

Forks