Need to get an xpath expression for the span inside the iframe. Need Help in getting XPath expression for span inside an Iframe popup.
i can get the iframe but getti
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.
//span [ancestor::iframe]
This will select all span elements which at some point have an ancestor iframe element.
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.
We can't access elements within an iframe
directly. We need to switch to iframe first.
I am using PHP Facebook webdriver and this is perfectly working for me:
$driver->get("http://www.example.com"); // containing an iframe
$iFrame = $driver->findElement(
WebDriverBy::xpath('//iframe[@name="iFrameName"]') //name or id or whatever by which we can access.
);
$driver->switchTo()->frame($iFrame);
Now, we can access that span
as:
$spanButton = $driver->findElement(
WebDriverBy::xpath('//span')
);