wson-dom-connector
v0.7.163
Published
Serialize DOM nodes to xPaths with wson.
Downloads
43
Maintainers
Readme
wson-dom-connector
WSON is a human-readable data-interchange format with support for cyclic structures. This module is an extension to wson that enables serializing DOM nodes to their xpaths and parsing those xpaths back to DOM nodes.
Possible Use Cases
- Store references to DOM elements between page reloads,
- Record DOM events to later simulate a user during automated test
(needs
wson-event-connector
).
Installation
npm install --save wson wson-dom-connector
Usage
wson-dom-conector can be used in a web browser via browserify...
var WSON = require("wson").Wson;
var domConnectors = require("wson-dom-connector");
var wson = new WSON({
connectors: domConnectors(window)
});
console.log(wson.stringify(document.body));
// [:HTMLBodyElement|/body`a1`e]
...or in node with any standard-compliant DOM implementation (e.g. jsdom).
var WSON = require("wson").Wson;
var domConnectors = require("wson-dom-connector");
var jsdom = require("jsdom");
var document = jsdom.jsdom("<body></body>")
var wson = new WSON({
connectors: domConnectors(document.defaultView)
});
console.log(wson.stringify(document.body));
// [:HTMLBodyElement|/body`a1`e]
API
Please refer to wson's documentation for further details.
License
Copyright © 2016 - 2019 Maciej Chałapuk. Released under MIT license.