2012-11-30 4 views
1

iframe 태그 아래에있는 데이터를 가져 오려고합니다. 본문 태그 아래의 데이터를 원합니다. 그러나 적절한 출력을 얻지 못했습니다. 여기 내 HTML 페이지가 다음과 같이 보입니다. 다음 :본문을 자바에서 iframe의 내용을 보유하는 방법을 얻으려면

<iframe id="sharetools-iframe" width="100%" height="100%" frameborder="0" style="z-index: 1000; position: relative; visibility: visible; " scrolling="no" allowtransparency="true" src="some url here"></iframe> 
#document 
<html><head><script type="text/javascript">window.WIDGET_ID = 'sharepopup';</script> 
<base href="href here"> 
<link rel="stylesheet" href="href here"> 
<script src="url here"></script> 

<script type="text/javascript" src="url here"></script></head> 
<body> 
body contents are here........ 
.............................. 
</div></div></body></html> 

나는 다음과 같은 코드를 사용하고 다음과 같이 여기

WebDriver webDriver = new FirefoxDriver(); 
webDriver.get("url to open"); 
String htmlPage = webDriver.getPageSource(); 
Tidy tidy = new Tidy(); 
InputStream inputStream = new ByteArrayInputStream(htmlPage.getBytes()); 
Document doc = tidy.parseDOM(inputStream, null); 
Element element = doc.getElementById("sharetools-iframe"); 

내가 요소 null.I를 얻고도 그것을 주조 입력 한 :

HTMLIFrameElement iframeElement = (HTMLIFrameElement) doc.getElementById("sharetools-iframe"); 

iframeElement를 null로 가져 오는 중입니다. 다음과 같이 나 또한 jsoup 파서를 사용했다

:

Document doc = Jsoup.parse(htmlPage); 
org.jsoup.nodes.Element iframeElement= doc.getElementById("sharetools-iframe"); 

여기가 iframeElement로 출력 <iframe id="sharetools-iframe" width="100%" height="100%" frameborder="0" style="z-index: 1000; position: relative; visibility: visible; " scrolling="no" allowtransparency="true" src="some url here"></iframe>하지만 본문 내용을받지을 얻고있다.

iframe의 본문 내용을 가져 오는 방법을 알려주세요.

+0

htmlPage의 내용을 확인 했습니까? – user314104

답변

2

iframe으로 전환 한 다음 콘텐츠와 상호 작용할 수 있습니다. 예 : body :

driver.switchTo().frame(driver.findElement(By.id("sharetools-iframe"))).findElement(By.tagName("body")); 
+0

감사합니다 Voffa.It 작동 중입니다. – dhananjay

관련 문제