Pure JS implementation of the DOM Level 3 XPath specification
Go to file
Martynas Bagdonas 1b88459724 Fix order for attribute nodes 2019-02-06 16:55:12 +02:00
dist Fix order for attribute nodes 2019-02-06 16:55:12 +02:00
src Fix order for attribute nodes 2019-02-06 16:55:12 +02:00
test Fix a typo in test/xhtml_test.html 2016-04-07 00:36:58 -04:00
.gitignore Add dist/ to the repository for Bower usage 2016-05-13 05:01:58 -04:00
.travis.yml Add .travis.yml for Travis CI 2016-02-16 23:16:12 -05:00
LICENSE Initial manual source code copied from Google code. The automatic github export tool failed. 2015-04-01 16:03:14 -04:00
README.md Add instructions for installing via NPM or Bower to README.md 2016-04-07 18:02:16 -04:00
bower.json Add bower.json for Bower compatibility 2016-03-29 06:03:41 -04:00
gulpfile.js Add "compile-node" to the default gulp tasks 2016-03-30 15:31:35 -04:00
package.json Fix order for attribute nodes 2019-02-06 16:55:12 +02:00


Wicked Good XPath

Build Status npm version


Wicked Good XPath is a Google-authored pure JavaScript implementation of the DOM Level 3 XPath specification. It enables XPath evaluation for HTML documents in every browser. We believe it to be the fastest XPath implementation available in JavaScript.


Download the latest wgxpath.install.js file and include it on your webpage with a script tag. For example:

<script src="wgxpath.install.js"></script>

Then call wgxpath.install() from your JavaScript code, which will ensure document.evaluate, the XPath evaluation function, is defined on the window object. To install the library on a different window, pass that window as an argument to the install function.

We provide an NPM package at https://www.npmjs.com/package/wicked-good-xpath. There's also another NPM package at https://www.npmjs.com/package/wgxpath.

To install via NPM or Bower, do

npm install wicked-good-xpath


bower install wicked-good-xpath

Building it Yourself

We use Gulp:

npm install

You can also run src/compile.sh if you want to use different versions of Closure Compiler / Closure Library.


Wicked Good XPath started as a Google Closure port of the JavaScript-XPath project by Cybozu Labs. At the time, JavaScript-XPath was the fastest JavaScript implementation of XPath available --- a whopping 10 times faster than Google's own AJAXSLT --- which made it a popular choice, notable for frontend web testing tools like Selenium and Web Puppeteer.

While it was fast, the code fell out of maintenance (last update was in 2007) so bugs were tough to get fixed. Also, since it wasn't written in Google Closure, it was tricky for us Googlers to integrate into our JavaScript applications. A rewrite was necessary.

However, we went beyond merely porting the library to Google Closure and fixing a couple bugs. We identified some significant additional performance improvements, such that our version runs about 30% faster than the original. On top of that, the Closure compiler was able to minify our code down to a mere 25K, 40% smaller than JavaScript-XPath's 42K (though it has grown a bit since). Finally, the code is structured and documented in a way that we believe will make future maintenance quicker and easier.