This project has moved and is read-only. For the latest updates, please go here.

Why are Input elements not part of a Form element


Why does this test fail?
    public void HAP_FormWithInput_InputIsChildOfForm()
        // Arrange
        var html = @"
<head> <title>Form Test</title> </head> <body>
<form method=""post"" name=""test"" action=""action"" />
<input type=""hidden"" name=""input1"" value=""value1"" />
        var doc = new HtmlDocument();
        var form = doc.DocumentNode.Descendants("form").Single();
        // Act
        var actual = form.ChildNodes.Count();
        // Assert
        Assert.AreEqual(1, actual);


DarthObiwan wrote Oct 10, 2012 at 12:55 AM

HAP does not duplicate how the DOM works. It exposes the true node nesting of HTML. Form exposing the child input elements is part of the DOM specification used by browsers and is not actually part of the HTML specification.

That being said in the future HAP may expose this.
For now you can do a query for any input nodes under form.

wrote Jan 1, 2013 at 11:09 AM

wrote Feb 22, 2013 at 2:46 AM