title: C# webbrowser control (executing all javascripts associated with form)
body: <p>I am trying to auto submit form using webbrowser control. I am using the following code to submit"</p>
  
  <pre><code>currentElement.InvokeMember("submit");
  </code></pre>
  
  <p>Now this methods works fine. But sometimes a form may have some javascript function that is called on button click at the time of submission. So let's say if a form has some button image called "Submit" and when a user presses it, a javascript function somefunction() is called and then form is submitted.</p>
  
  <p>Problem is when I use the above method InvokeMember then it only submits the form and doesn't execute associated scripts (in this case somefunction()) and I have to manually write code</p>
  
  <pre><code>webBrowser1.Document.InvokeScript("somefunction");
  </code></pre>
  
  <p>But this requires that I know before hand if there is some function. Is there any way I submit form and it will automatically run all associated javascript?</p>
  
  <p>And I don't know button name or ID either which is clicked by user to submit form. Because in some cases it may not even have ID or name for e.g.</p>
  
  <pre><code>&lt;span class="btn" onclick="somefunction()"&gt;
  &lt;img style="cursor:pointer" title="Submit" alt="Submit" src="http://stackoverflow.com/imagesbutton.png?2012"&gt;
  &lt;div id="s" style=""&gt;&lt;/div&gt;
  &lt;/span&gt;
  </code></pre>