Created
December 28, 2014 20:12
-
-
Save e-oz/52af2b1f998fed1e9520 to your computer and use it in GitHub Desktop.
Protractor locator to find element(s) by value of attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
by.addLocator('attr', | |
/** | |
* Find element(s), where attribute = value | |
* @param {string} attr | |
* @param {string} value | |
* @param {Element} [parentElement=] | |
* @returns {Array.<Element>} | |
*/ | |
function (attr, value, parentElement) { | |
parentElement = parentElement || document; | |
var nodes = parentElement.querySelectorAll('[' + attr + ']'); | |
return Array.prototype.filter.call(nodes, function (node) { | |
return (node.getAttribute(attr) === value); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of usage: