Last active
June 14, 2020 09:04
-
-
Save sandipchitale/3a4f5143d6592f8514d1d4015aaefb96 to your computer and use it in GitHub Desktop.
Get xPath of document.activeElement
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
{ let e = document.activeElement; let pchain = []; while (e.tagName !== 'BODY') { pchain.unshift(e.tagName + '[' + (Array.prototype.indexOf.call(e.parentElement.querySelectorAll(':scope > ' + e.tagName), e) + 1) + ']'); e = e.parentElement; } ; '/html/body/' + pchain.join('/').toLowerCase() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment