Alexander Cyberman
Alexander Cyberman

Reputation: 2178

How to get by javafx webview content iframe loaded page?

In an open page loaded frame:

 <iframe id="wikipedia" src="http://en.wikipedia.org"></iframe>

Trying to get to the content:

Document document = webEngine.getDocument();
Element elementById = document.getElementById("wikipedia");
System.out.println(elementById.getTextContent());

But do not achieve results ...

Upvotes: 1

Views: 2510

Answers (1)

GregKo
GregKo

Reputation: 179

The following code works fine with javafx2:

Document doc = webEngine.getDocument();
HTMLIFrameElement iframeElement = (HTMLIFrameElement) doc.getElementById("wikipedia");
Document iframeContentDoc = iframeElement.getContentDocument();
Element rootElement = iframeContentDoc.getDocumentElement();
System.out.println(rootElement.getTextContent());

Upvotes: 4

Related Questions