how to access xpath in js
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
how to access xpath in js
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
xpath in javascript
/*
In Browser console use
$x function to use the xpath
*/
javascript xpath
const fs = require("fs");const xpath = require("xpath-html"); // Assuming you have an html file locally,// Here is the content that I scraped from www.shopback.sgconst html = fs.readFileSync(`${__dirname}/shopback.html`, "utf8"); // Don't worry about the input much,// you are able to use the HTML response of an HTTP request,// as long as the argument is a string type, everything should be fine.const node = xpath.fromPageSource(html).findElement("//*[contains(text(), 'with love')]"); console.log(`The matched tag name is "${node.getTagName()}"`);console.log(`Your full text is "${node.getText()}"`);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us