2

I'm working with HtmlDocument and HtmlWeb. I usually get the form element by its id using:

HtmlDocument doc = new HtmlDocument();

//get the form
doc.LoadHtml(htmlPreviousForm);
var form = doc.GetElementbyId("postingForm");

However, the page that I'm working the form that I want doesn't have name, id, or class:

<form action="test.php" method="post">
    <button type="submit" name="go" value="[x]" title="delete">x</button>
</form>

How can I get the action of this form using HtmlDocument?

user6824563
  • 675
  • 5
  • 23
  • 42

1 Answers1

1

Instead of getting the form by id you can use SelectSingleNode

var form = htmlDoc.DocumentNode.SelectSingleNode("//form");
hardkoded
  • 15,907
  • 3
  • 45
  • 56