HtmlUnit doesn't handle a potentially defined default namespace consequently. When a response is received that contains XHTML content the sent content-type of the response decides whether this is parsed by HtmlUnit as HTML page or as XHTML page.
In first case, the namespace URI specifiey by the default namespace is not set at the document element and its descendants. In the second case it will be set correctly.
This solution might be correct since HTML doesn't know any namespace. But when a new HTML element is constructed by a DOM Level 2 method (e.g. createElementNS) the given namespace is unconditionally set, even if the element is attached to a pure HTML page. This may result in a DOM tree, which defines a default namespace at its root element but where only the elements created with an explicitely given namespace have a namespace URI set even if it's the default one.
As possible solution would be to consequently ignore the XHTML namespace URI when creating a new HTML element that will be attached to a pure HTML page - the HTMLParser already uses a similar logic when parsing a HTML page.
Thus, all nodes of DOM tree of a pure HTML page will have no namespaceURI set which also simplifies XPath queries since XPath doesn't know any default namespace.
Inconsistency demo test