2012-02-03 18 views
9

Estoy escribiendo pruebas para una aplicación heredada en la que hay un iFrame dentro del documento principal y luego otro iFrame dentro de ese. Por lo que la jerarquía es:Búsqueda de iFrame anidado utilizando Selenium 2

Html Div (id = tileSpace) 
    iFrame (id = ContentContainer) 
    iFrame (id = Content) 
     Elements 

Este es mi código (estoy usando C#)

RemoteWebDriver driver = new InternetExplorerDriver(); 
var tileSpace = driver.FindElement(By.Id("tileSpace")); 
var firstIFrame = tileSpace.FindElement(By.Id("ContentContainer")); 
var contentIFrame = firstIFrame.FindElement(By.Id("Content")); 

El problema es que no estoy en condiciones de alcanzar el segundo nivel de marco flotante es decir contentIFrame

Todas las ideas ?

Respuesta

19

Actualmente estoy probando en un sitio web similar. (marcos flotantes anidados dentro del documento principal)

<div> 
    <iframe> 
     <iframe><iframe/> 
    <iframe/> 
</div> 

Parece que no está utilizando el frame switching method dispuesto en el API. Este podría ser el problema.

Esto es lo que estoy haciendo, funciona bien para mí.

//make sure it is in the main document right now 
driver.SwitchTo().DefaultContent(); 

//find the outer frame, and use switch to frame method 
IWebElement containerFrame = driver.FindElement(By.Id("ContentContainer")); 
driver.SwitchTo().Frame(containerFrame); 

//you are now in iframe "ContentContainer", then find the nested iframe inside 
IWebElement contentFrame = driver.FindElement(By.Id("Content")); 
driver.SwitchTo().Frame(contentFrame); 

//you are now in iframe "Content", then find the elements you want in the nested frame now 
IWebElement foo = driver.FindElement(By.Id("foo")); 
+0

Gracias! funcionó muy bien – user356247

0

Try a continuación código:

//Switch to required frame 
    driver.SwitchTo().Frame("ContentContainer").SwitchTo().Frame("Content"); 

    //find and do the action on required elements 

    //Then come out of the iFrame 
    driver.SwitchTo().DefaultContent(); 
Cuestiones relacionadas