Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I submit a form inside a WebBrowser control?

How can I create a program with C# to submit the form(in the web browser CONTROL in windows Apps)automaticlly ?

like image 744
Mohammad Reza Tavakkol Avatar asked Feb 19 '10 20:02

Mohammad Reza Tavakkol


People also ask

How to use WebBrowser control in c# windows application?

To do so, right-click on the WebBrowser control, and select Properties. This action launches the Properties window. Feel free to set any properties you like. The Url property represents the web page a WebBrowser displays.

What is WebBrowser control?

The WebBrowser control provides a managed wrapper for the WebBrowser ActiveX control. The managed wrapper lets you display Web pages in your Windows Forms client applications.


1 Answers

The WebBrowser control has a Document property, which returns an HtmlDocument. The HtmlDocument has several members you can use to traverse and manipulate the DOM.

Once you've used these methods to find the form, you can use InvokeMember to call the form's submit method.

If you know the page has a single form:

foreach (HtmlElement form in webBrowser1.Document.Forms)
    form.InvokeMember("submit");

If you know the ID of the form you would like to submit:

HtmlElement form = webBrowser1.Document.GetElementById("FormID");
if (form != null)
    form.InvokeMember("submit");
like image 195
meagar Avatar answered Sep 20 '22 12:09

meagar