I'm trying to use xpath on a page but am getting the error Uncaught DOMException: Failed to execute 'iterateNext' on 'XPathResult': The document has mutated since the result was returned.
xpath = document.evalutate('//a', document)
xpath.iterateNext()
What's wrong?
The problem was that the page is mutated between the time the XPathResult object is generated and the time when you access an object in it.
Instead use snapshots
xpath = document.evaluate('//td/a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
xpath.snapshotItem(0)
xpath.snapshotItem(1)
If your propose is read only, it's possible to clone the context node:
xpath = document.evaluate('//a', document.cloneNode(true))
xpath.iterateNext()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With