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
  • 36,338
  • 80
  • 323
  • 498
Jack
  • 16,276
  • 55
  • 159
  • 284
  • 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

2

Try this:

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