You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above XPath would do the job, but with the current implementation we are forced to either traverse the DOM using good old page.evaluate() or known how many elements would be matched beforehand and issue n separate XPath queries in the form of (expression)[1..n]. Or just run XPath in page.evaluate:
await page.evaluate(() => {
function $x(expression) {
let result = [];
let element = null;
let elements = document.evaluate(expression, document, null, XPathResult.ANY_TYPE, null);
while ((element = elements.iterateNext()) !== null) {
result.push(element);
}
return result;
}
return $x('id("wikiArticle")/table[@class="standard-table"]//td[1]/code[starts-with(., "ANY_")]').map(
(element) => {
return element.textContent;
}
);
});
// ["ANY_TYPE", "ANY_UNORDERED_NODE_TYPE"]
It would be great to have more capable XPath querying abilities before PPTR 1.0.0 is released.
The text was updated successfully, but these errors were encountered:
Right now, the current
page.xpath()
implementation only returns the first matched element.I find this implementation somewhat restrictive, specially considering it's tied to
ElementHandle
.For instance, if we wish to find all
ANY_*
XPath result type constants on the MDN website:The above XPath would do the job, but with the current implementation we are forced to either traverse the DOM using good old
page.evaluate()
or known how many elements would be matched beforehand and issue n separate XPath queries in the form of(expression)[1..n]
. Or just run XPath inpage.evaluate
:It would be great to have more capable XPath querying abilities before PPTR 1.0.0 is released.
The text was updated successfully, but these errors were encountered: