2011-10-27 13 views
7

Necesita obtener una expresión xpath para el span dentro del iframe. Necesita ayuda para obtener la expresión XPath para span dentro de una ventana emergente Iframe.Necesita ayuda para obtener la expresión XPath para span dentro de una ventana flotante Iframe

puedo conseguir el iframe pero conseguir/html/cuerpo en el interior de marco flotante que no está ocurriendo ninguna ayuda sería apreciada

<div class="gwt-PopupPanelGlass" style="position: absolute; left: 0px; top: 0px; visibility: visible; display: block; width: 1680px; height: 222px;"></div> 
<div class="gwt-PopupPanel" style="left: 439px; top: 0px; visibility: visible; position: absolute; overflow: visible;"> 
<div class="popupContent"> 
<div class="ph-PopupDialog" style="position: relative; width: 800px; height: 220px;"> 
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex;">&nbsp;</div> 
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; bottom: 0px;"> 
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;"> 
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex;">&nbsp;</div> 
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; height: 32px;"> 
<div style="position: absolute; overflow: hidden; left: 0px; top: 32px; right: 0px; bottom: 0px;"> 
<div class="ph-PopupDialog-content" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;"> 
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex;">&nbsp;</div> 
<div style="position: absolute; overflow: hidden; left: 5px; top: 5px; right: 5px; bottom: 5px;"> 
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;"> 
<div> 
<iframe class="gwt-Frame ph-PaymentFrame" name="paymentFrame" src="javascript:''"> 
<html> 
<head> 
<body onload="pageLoaded();"> 
<div class="ph-View"> 
<div class="container_24 form-grid"> 
<div class="container_24 form-grid"> 
<div class="container_24 form-grid"> 
<div class="container_24 form-grid"> 
<div class="container_24 form-grid"> 
<div class="grid_12"> 
<div class="ph-ButtonPanel ph-ButtonPanel-undecorated"> 
<a class="ph-Button ph-Button-button" onclick="submit();return false;" style="float: right; margin-left: 5px;" href="#"> 
<a class="ph-Button ph-Button-button" onclick="cancel();return false;" style="float: right; margin-left: 5px;" href="#"> 
<span>Cancel</span> 
</a> 
</div> 
</div> 
</div> 
</div> 
</body> 

`

Respuesta

1

Uso:

//iframe//span 

Esto selecciona todos los elementos span que es un descendiente de cualquier elemento iframe en el documento XML.

0
//span [ancestor::iframe] 

Esto seleccionará todos los elementos span que en algún momento tener un elemento ancestro iframe

8

Los elementos en iframe están, de hecho, en otra página. por lo tanto, primero debe buscar la dirección de esa página, que es el valor de src value of iframe, cargarla y luego acceder al elemento en esa página.

5

Tiene que establecer el alcance de la XPath a la propiedad contentDocument del marco flotante:

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

No podemos tener acceso a elementos dentro de un iframe directamente. Necesitamos pasar primero al iframe.

Estoy usando el controlador PHP Facebook y esto funciona perfectamente para mí.

$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); 

Ahora, podemos acceder a esa span como,

$spanButton = $driver->findElement(
      WebDriverBy::xpath('//span') 
     ); 

Espero que esto pueda ayudar a alguien!

Cuestiones relacionadas