Skip to content

Commit

Permalink
HtmlPage getBody returns the body and not the frameset
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Nov 2, 2024
1 parent 8607b1a commit 5ad1198
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/org/htmlunit/javascript/host/dom/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@
import org.htmlunit.html.HtmlAnchor;
import org.htmlunit.html.HtmlArea;
import org.htmlunit.html.HtmlAttributeChangeEvent;
import org.htmlunit.html.HtmlBody;
import org.htmlunit.html.HtmlElement;
import org.htmlunit.html.HtmlEmbed;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlFrameSet;
import org.htmlunit.html.HtmlImage;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.html.HtmlRb;
Expand Down Expand Up @@ -825,10 +827,21 @@ public HTMLCollection getApplets() {
public HTMLElement getBody() {
final Page page = getPage();
if (page instanceof HtmlPage) {
final HtmlElement body = ((HtmlPage) page).getBody();
final HtmlPage htmlPage = (HtmlPage) page;
final HtmlElement body = htmlPage.getBody();
if (body != null) {
return body.getScriptableObject();
}

// strange but this returns the frameset element
final DomElement doc = htmlPage.getDocumentElement();
if (doc != null) {
for (final DomNode node : doc.getChildren()) {
if (node instanceof HtmlFrameSet) {
return (HTMLElement) node.getScriptableObject();
}
}
}
}
return null;
}
Expand Down

0 comments on commit 5ad1198

Please sign in to comment.