I have a target html portion from which I want to find element via XPath. It contains an element which has id id1. Although elements with id1 are also present outside the target element down in the page, but I want to find only inside the target html.
I have tried :
var targetHtml = document.getElementById('targetHtmlId')
var xPath = '//div[@id="id1"]/div[1]'
document.evaluate(xPath , targetHtml , null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
It searches from the whole page (document) and not specifically from the targetHtml. Can anyone share code which works, even ChatGPT could not provide correct answer.