Created
August 1, 2018 12:27
-
-
Save dmjcomdem/b82515423086c3d5110041015faf499c to your computer and use it in GitHub Desktop.
convert Xpath to CSS
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
function xPathToCss(xpath) { | |
return xpath | |
.replace(/\[(\d+?)\]/g, function(s,m1){ return '['+(m1-1)+']'; }) | |
.replace(/\/{2}/g, '') | |
.replace(/\/+/g, ' > ') | |
.replace(/@/g, '') | |
.replace(/\[(\d+)\]/g, ':eq($1)') | |
.replace(/^\s+/, ''); | |
} | |
xPathToCss('[@id="userjsGrid"]/div[1]/table/tbody/tr[2]/td[6]/input') | |
// => [id="userjsGrid"] > div:eq(0) > table > tbody > tr:eq(1) > td:eq(5) > input | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment