shapiroronny · GitHub

In one of the previous versions a breaking change with HtmlInput.setAttribute was introduced.
Currently, when changing type of HtmlInput a new instance is created and the instance worked on is no longer attached.
Looks like this behavior is intended but causes undesired side effects as the user has absolutely no way knowing they are working on a stale object.

(HtmlElementBuilder is a helper class we created, it basically just creates a StringWebResponse and passes it to to PageCreator)

Example 1 :

@Test
public void testInput() {
        HtmlPage page = HtmlElementBuilder.createPageFromString("<html><head></head><body></body></html>");
        HtmlElement input = (HtmlElement) page.createElement("input");
        input.setAttribute("type", "hidden");
        input.setAttribute("name", "test");
        page.getBody().appendChild(input);
        System.out.println(page.asXml());
}

Which result in this result:

@Test
public void testInput() {
        HtmlPage page = HtmlElementBuilder.createPageFromString("<html><head></head><body></body></html>");
        HtmlElement input = (HtmlElement) page.createElement("input");
        page.getBody().appendChild(input);
        input.setAttribute("type", "hidden");
        input.setAttribute("name", "test");
        System.out.println(page.asXml());
    }

Results in:

"

Read the original on github.com ↗