When I use querySelectorAll
, I can find 138 td
nodes in my sample document.
Array.from(document.querySelectorAll('td')).length
138
When I do the same with XPath, I get no result:
Array.from(document.evaluate(".//td", document.body, null, XPathResult.ANY_TYPE, null)).length
0
Although there is at least one match:
document.evaluate(".//td", document.body, null, XPathResult.ANY_TYPE, null).iterateNext().nodeName
"TD"
The problem seems to be that Array.from
can not iterate over a XPathResult
. Even this returns 0:
Array.from(document.evaluate('.', document.body, null, XPathResult.ANY_TYPE, null)).length
0
How to make a XPathResult
suitable for Array.from
?