@cypress/unique-selector v2.1.1
unique-selector
Given a DOM node, return a unique CSS selector matching only that element. This is particularly useful when tracking in custom variables in analytics:
document.addEventListener('click', function(event) {
var selector = unique(event.target);
_gaq.push(['_trackEvent', 'Engagement', 'Click', selector]);
}, false);Selector uniqueness is determined based on the given element's root node. Elements rendered within Shadow DOM will derive a selector unique within the associated ShadowRoot context. Otherwise, a selector unique within an element's owning document will be derived.
Installation
Options
e.g.1 DomElement = <span id="test"></span>
import unique from 'unique-selector';
// Optional Options
options = {
// Array of selector types based on which the unique selector will generate
selectorTypes : [ 'ID', 'Class', 'Tag', 'NthChild' ]
}
unique( DomElement, options ); // #teste.g.2 DomElement = <span test="2"></span>
import unique from 'unique-selector';
// Optional Options
options = {
// Array of selector types based on which the unique selector will be generate
selectorTypes : [ 'Attributes' ]
}
unique( DomElement, options ); // [test="2"]Tests
$ npm run testContributing
Feel free to open issues, make suggestions or send PRs. This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code.
Contact
Avraam Mavridis : @avraamakis
Eric Clemmons : @ericclemmons
Releases
v2.1.0
v0.1.0
- Big refactor/rewrite using es6
- More test + Change the test script
- Script to compile es6 to es5 using babel
- Ability to pass options for the selectorTypes based on which the unique selector will be generated, see the options
v0.0.4
- Handle extra whitespace in
className(#9)
- Handle extra whitespace in
v0.0.3
- Add support for various
<form>elements (#2)
- Add support for various
v0.0.2
- Fix bug with
nth-childcalculation
- Fix bug with
v0.0.1
- Initial release
License
MIT


