In my sample document, I found 138 nodes with the tag td
using querySelectorAll
.
Array.from(document.querySelectorAll('td')).length
138
However, when I tried to do the same using XPath, I did not get any result:
Array.from(document.evaluate(".//td", document.body, null, XPathResult.ANY_TYPE, null)).length
0
Despite this, there is at least one match:
document.evaluate(".//td", document.body, null, XPathResult.ANY_TYPE, null).iterateNext().nodeName
"TD"
The issue seems to be that Array.from
cannot handle a XPathResult
. Even when trying to iterate over it directly, I still get 0 results:
Array.from(document.evaluate('.', document.body, null, XPathResult.ANY_TYPE, null)).length
0
Is there a way to make a XPathResult
compatible with Array.from
?