Get xPath cmd from textPath
by jonahe
HTML
<h2>See console</h2>
JavaScript 1.7
let textPath_1 = "co_worker_production,buttons,next_button"
const getXPathExpression = (textPath) => {
const parts = textPath.split(",");
return parts.reduce((xPathExpr, partOrTxtId, index) => {
xPathExpr += `*[@id="${partOrTxtId}"]/`;
if(parts.length -1 === index) return xPathExpr + `text()`;
else return xPathExpr;
}, "//");
}
console.log(getXPathExpression(textPath_1))