2012-02-03 12 views
9

Sto scrivendo i test per un'applicazione legacy in cui è presente un iFrame all'interno del documento principale e quindi un altro iFrame all'interno di esso. Quindi la gerarchia è:Ricerca di iFrame nidificati con selenio 2

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

Questo è il mio codice (sto 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")); 

Il problema è, io sono in grado di raggiungere il 2 ° livello iFrame cioè contentIFrame

Tutte le idee ?

risposta

19

Attualmente sto testando su un sito simile. (iframe nidificati all'interno del documento principale)

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

Sembra che non si utilizza il frame switching method previsto Api. Questo potrebbe essere il problema.

Ecco cosa sto facendo, funziona bene per me.

//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

Grazie! ha funzionato molto bene – user356247

0

Prova sottostante Codice:

//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(); 
Problemi correlati