# nightmare-xpath

> Nightmare plugin to select nodes by xpath expression

Latest version **3.0.0** (published 2020-09-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install nightmare-xpath
pnpm add nightmare-xpath
yarn add nightmare-xpath
bun add nightmare-xpath
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2020-09-25 |
| First published | 2015-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Maintainers | iamthes |
| Keywords | nightmare-plugin, nightmare, xpath |

## Links

- npm: https://www.npmjs.com/package/nightmare-xpath
- Repository: https://github.com/unlight/nightmare-xpath
- Issues: https://github.com/unlight/nightmare-xpath/issues
- npm.io page: https://npm.io/package/nightmare-xpath

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2020-09-25
- 2.0.2 — 2016-10-28
- 2.0.1 — 2016-06-25
- 2.0.0 — 2015-10-01
- 1.0.1 — 2015-03-25
- 1.0.0 — 2015-03-23

## README

# nightmare-xpath

Nightmare plugin to select nodes by xpath expression.

## INSTALL

This will install plugin `nightmare-xpath` for Nightmare 3.X:

```sh
npm install --save-dev nightmare-xpath
```

**Note:** If you are looking for plugin for Nightmare 1.X, then use:

```sh
npm install nightmare-xpath@1
```

## USAGE

```js
const Nightmare = require('nightmare');
require('nightmare-xpath')(Nightmare);

const links = await Nightmare()
    .goto('http://example.com/')
    .xpath('//a[@href]', function (node) {
        // We cannot return DOM element to nodejs,
        // we must return serializable object or primitive.
        // If function is omitted, node.toString() will be used.
        return node.href;
    })
    .then();

console.log(links); // ['https://www.iana.org/domains/example']
```

## API

`xpath(selector: string, handler?: (Node: node) => any): Array<any>`

#### selector

Type: `string`

XPath expression.

#### handler

Type: `function`  
Optional: Yes  
Signature: `(Node: node) => any`

This function be called on each result of `XPathResult`.
We cannot return DOM element to nodejs,
we must return serializable object or primitive.
If function is omitted, node.toString() will be used.

## RESOURCES

-   https://developer.mozilla.org/ru/docs/Web/API/Document/evaluate

---
_Source: https://npm.io/package/nightmare-xpath · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
