2012-02-03 6 views
9

주 문서에 iFrame이 있고 그 안에 다른 iFrame이있는 레거시 응용 프로그램에 대한 테스트를 작성하고 있습니다. 따라서 계층 구조는 다음과 같습니다Selenium 2를 사용하여 중첩 된 iFrame 찾기

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

이이 문제가

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

, 나는 2 수준 iframe이 예 contentIFrame

어떤 아이디어에 도달 할 수없는 나는 (내가 C#을 사용하고있다) 내 코드입니다 ?

답변

19

현재 비슷한 웹 사이트에서 테스트 중입니다. (주 문서 내부에 중첩 된 iframe을)은

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

당신이 API의 제공 frame switching method를 사용하지 않는 것 같다. 이것은 문제 일 수 있습니다.

내가하는 일은 다음과 같습니다. 제대로 작동합니다. 코드 아래

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

감사합니다! 아주 잘 했어. – user356247

0

시도 :

//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(); 
관련 문제