Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/main/java/org/htmlunit/html/HtmlFormUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,19 @@ public static Page submit(HtmlForm htmlForm, HtmlElement submitElement) throws I
return submitElement.click();
}

try {
htmlForm.submit((SubmittableElement) submitElement);
} finally {
// The HtmlForm submit doesn't really do anything. It just adds a "LoadJob"
// to an internal queue. What we are doing here is manually forcing the load of
// the response for that submit LoadJob and then getting the enclosing page
// from the current window on the WebClient, allowing us to return the correct
// HtmlPage object to the test.
webClient.loadDownloadedResponses();
Page resultPage = webClient.getCurrentWindow().getEnclosedPage();
htmlForm.submit((SubmittableElement) submitElement);
// The HtmlForm submit doesn't really do anything. It just adds a "LoadJob"
// to an internal queue. What we are doing here is manually forcing the load of
// the response for that submit LoadJob and then getting the enclosing page
// from the current window on the WebClient, allowing us to return the correct
// HtmlPage object to the test.
webClient.loadDownloadedResponses();
Page resultPage = webClient.getCurrentWindow().getEnclosedPage();

if (resultPage == htmlPage) {
return HtmlElementUtil.click(submitElement);
} else {
return resultPage;
}
if (resultPage == htmlPage) {
return HtmlElementUtil.click(submitElement);
} else {
return resultPage;
}
} finally {
// Make sure all background JS has executed.
Expand Down Expand Up @@ -131,4 +128,7 @@ public static HtmlButton getButtonByCaption(final HtmlForm htmlForm, final Strin
}
throw new ElementNotFoundException("button", "caption", caption);
}

private HtmlFormUtil() {}

}