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
  • 735
  • 6
  • 25
  • 47

1 Answers1

1

Instead of getting the form by id you can use SelectSingleNode

var form = htmlDoc.DocumentNode.SelectSingleNode("//form");
hardkoded
  • 18,915
  • 3
  • 52
  • 64