1

how to programmatically set an input an element value inside a WebBrowser control?

For example, I have an HTML page, like:

<form method="post" action="...aspx" enctype="multipart/form-data" id="mainForm">
    <input type="file" id="file" />
    <input type="submit" id="submit" value="Submit it" />
</form>

How do I to submit it via C# code? I tried something:

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
{
   var doc = webBrowser1.Document;
   var input = doc.GetElementById("file");
   input.SetAttribute("value", @"C:\foo.baa");
   doc.GetElementById("mainForm").InvokeMember("submit");
}

but it does not working, the value of input is not setted and the form is not submited. I hope this is clean. Thanks in advance.

NoWar
  • 34,755
  • 78
  • 302
  • 475
Jack
  • 15,539
  • 54
  • 145
  • 264
  • may be this : http://stackoverflow.com/questions/1539685/how-programmatically-submit-a-form-without-a-submit-button-in-webbrowser – Zaki Feb 02 '12 at 16:54
  • Have you registered `webBrowser1_DocumentCompleted` to receive `DocumentCompleted` events? Is it actually getting to `webBrowser1_DocumentCompleted`? – Nick Smith Feb 02 '12 at 18:10

1 Answers1

1

Try this:

HtmlElement loBtn = (HtmlElement)loWebBrowser.Document.GetElementById("btnSubmit");
loBtn .InvokeMember("click");
Marcos
  • 80
  • 6