반응형
Handling iFrames using WebDriver
inline frame은 현재의 HTML 문서 내에 다른 문서를 넣을 때 사용됩니다. 즉 iframe은 웹페이지 안에 있는 웹페이지를 말하는거죠. iframe은 별도로 DOM을 가지고 있습니다.
iframe을 사용하는 HTML 소스코드는 아래와 같이 사용하시면 됩니다
위의 코드를 보면 iframe안에 또 다른 iframe이 있는 걸 보실 수 있을 겁니다. 안쪽의 iframe으로 가려면 바깥쪽의 iframe 을 지나가야 되고 또 그 안쪽의 iframe 안에도 body가 있습니다.
그리고 나서 다시 안쪽의 iframe은 을 나와서 바깥쪽 iframe 까지 나오면 이제 OK 버튼을 보게 됩니다. 테스트를 작성하려면 이 과정을 거쳐야 합니다. iframe 안에 있는 element에 직접 접근하는 것은 가능하지 않습니다. iframe은 자신만의 DOM element를 가지고 있어서 그 안의 element들을 다루려면 switch to 를 해서 접근해야 합니다.
Selects the frame 1
driver.switchTo().frame("frame1");
Selects the frame2
driver.switchTo().frame("frame2");
Switching back to the parent window
driver.switchTo().defaultContent(); // 이제 iframe 바깥으로 완전히 빠져 나온 겁니다.
iframe의 value를 알지 못할 때도 있는데요. 그럴 때는 아래와 같이 tagName 메소드를 사요ㅇ해서 그 name을 얻을 수 있습니다.
driver.switchTo().frame(driver.findElements(By.tagName("iframe").get(0));
아래 메소드를 사용해서 iframe을 선택하실 수 있습니다.
- frame(index)
- frame(Name of Frame [or] Id of the frame
- frame(WebElement frameElement)
- defaultContent()
반응형
'TDD Project > Selenium Web Driver' 카테고리의 다른 글
[Selenium] 두개의 시나리오나 여러 브라우저 작업을 한개의 suite 로 처리하기 (1) | 2014.02.02 |
---|---|
[Selenium] IE 브라우저 사용할 때 지켜야 할 점들 (2) | 2014.01.27 |
[Selenium] Select Option 관련 로직 정리 (0) | 2014.01.27 |
Selenium WebDriver 작업시 유용한 로직 - Pagination 등 (1) | 2013.12.16 |
Selenium WebDriver - Alert Control, Escape key (0) | 2013.12.06 |
Selenium WebDriver CSS Selector Tip - List<WebElement> (0) | 2013.12.04 |
Selenium WebDriver 에서 JavascriptExecutor 사용할 때 유념해야 될 상황 (0) | 2013.12.02 |
Page Objects in Selenium 2 (Web Driver) 소스 분석 (with Page Objects) 04 (0) | 2013.10.30 |
Page Objects in Selenium 2 (Web Driver) 소스 분석 (with Page Objects) 03 (0) | 2013.10.27 |
Page Objects in Selenium 2 (Web Driver) 소스 분석 (with Page Objects) 02 (0) | 2013.10.25 |