Last active
November 29, 2018 23:20
-
-
Save e-oz/5a567a4a059aa4eb7768 to your computer and use it in GitHub Desktop.
Protractor locator to find <a> element by href attribute
This file contains 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('link', | |
/** | |
* Find <a> element by href attribute | |
* @param {string} href | |
* @param {Node} [parentElement=] | |
* @returns {Array.<Node>} | |
*/ | |
function (href, parentElement) { | |
parentElement = parentElement || document; | |
var links = parentElement.querySelectorAll('a'); | |
return Array.prototype.filter.call(links, function (link) { | |
return (link.href && ((link.href === href) || (link.href === (link.baseURI + href)))); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@vlajos i'm 2 years late but that comment got me like
:fire: