Skip to content

Instantly share code, notes, and snippets.

@e-oz
Created December 28, 2014 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e-oz/52af2b1f998fed1e9520 to your computer and use it in GitHub Desktop.
Save e-oz/52af2b1f998fed1e9520 to your computer and use it in GitHub Desktop.
Protractor locator to find element(s) by value of attribute
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);
});
});
@e-oz
Copy link
Author

e-oz commented Dec 28, 2014

Example of usage:

expect(element(by.attr('ng-click', 'exampleMethod()')).isDisplayed()).toBe(true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment