The following prints a single input element to console in Chrome:
const form = document.createElement("form");
form.appendChild(document.createElement("input"));
form.remove();
console.log(form.elements);
but in HtmlUnit form.elements becomes empty once form is detached from DOM.
Seems to come from 00ce1ab#diff-ccb37821109ece9c771414e5408dc628f9baf4e80e0ad5c5d16f93e5576ef2a6R609
If the form is detached it would make sense to iterate over its children instead of the whole page.