Form:
<form method="POST" name="contactform" action="form-handler.php">
<label for='name'>Name:</label>
<input type="text" name="name" />
<label for='email'>Contact Number:</label>
<input type="text" name="phone" />
<label for='phone'>Email:</label>
<input type="text" name="email" />
<label for='message'>Requirements:</label>
<textarea name="message"></textarea>
<input type="submit" value="Submit" name="submit" class="quoteButton" />
</form>
Code:
HtmlNode.ElementsFlags.Remove("form");
HtmlNodeCollection fromNodes = doc.DocumentNode.SelectNodes("//form");
foreach (HtmlNode formNode in fromNodes)
{
var inputs = formNode.SelectNodes(".//input");
}
"//input" works and when I check the children xpath I see:
/html[1]/body[1]/div[1]/div[3]/div[2]/div[1]/div[1]/input[2]
Which means, according to HAP, form doesn't even include the input!
".//input" that selects subnodes of the current formNode doesn't work (returns null)!
How to fix this I added the following but it doesn't work
HtmlNode.ElementsFlags.Remove("form");
Any idea?
Edit (+Example):
In the next sample the inputs variable is also null.
var doc = new HtmlDocument();
doc.LoadHtml(@"
<!DOCTYPE html>
<html>
<head>
<title>Form Test</title>
</head>
<body>
<form>
<input type=""text"" />
<input type=""reset"" />
<input type=""submit"" />
</form>
</body>
</html>
");
HtmlNode.ElementsFlags.Remove("form");
IEnumerable<HtmlNode> fromNodes = doc.DocumentNode.Descendants("form");
foreach (HtmlNode formNode in fromNodes)
{
var inputs = formNode.SelectNodes(".//input");
}