https://github.com/featurist/css-to-xpath
Convert CSS selectors to XPaths, in JavaScript
https://github.com/featurist/css-to-xpath
Last synced: about 2 months ago
JSON representation
Convert CSS selectors to XPaths, in JavaScript
- Host: GitHub
- URL: https://github.com/featurist/css-to-xpath
- Owner: featurist
- License: bsd-2-clause
- Created: 2014-01-02T15:35:52.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-10-11T16:51:24.000Z (over 8 years ago)
- Last Synced: 2025-02-20T20:47:42.672Z (2 months ago)
- Language: PogoScript
- Size: 152 KB
- Stars: 44
- Watchers: 7
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# css-to-xpath
Converts [CSS3 selectors](http://www.w3.org/TR/css3-selectors/#selectors) to their XPath equivalents.
[](http://travis-ci.org/featurist/css-to-xpath)
### Usage
```js
var cssToXPath = require('css-to-xpath');cssToXPath('p:not(:has(a.x))');
```
...returns the string:
```
.//p[not(.//a[contains(concat(' ', normalize-space(./@class), ' '), ' x ')])]
```Or if you want to continue building the XPath with xpath-builder:
```js
var cssToXPath = require('css-to-xpath');var xpathBuilderObject = cssToXPath.parse('p:not(:has(a.x))');
xpathBuilderObject = xpathBuilderObject.where(cssToXPath.xPathBuilder.text().equals('Some Text Content'));// And get the XPath string
xpathBuilderObject.toXPath();
```### How?
css-to-xpath parses css selectors using [bo-selector](https://github.com/featurist/bo-selector) and turns them into xpaths using [xpath-builder](https://github.com/featurist/xpath-builder)
### Install
npm install css-to-xpath
### License
BSD