Need Help in getting XPath expression for span inside an Iframe popup

Elements in iframe are in fact in another page. so you should first find address of that page which is value of src value of iframe and load it and then access the element in that page.


You need to set the scope of the xpath to the iframe's contentDocument property:

var iframe = document.getElementsByTagName("iframe")[0];
var theFirstSpan = document.evaluate('//span', iframe.contentDocument,
         null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue

Use:

//iframe//span

This selects every span element that is a descendent of any iframe element in the XML document.