I am trying to auto submit form using webbrowser control. I am using the following code to submit"
currentElement.InvokeMember("submit");
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.
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
webBrowser1.Document.InvokeScript("somefunction");
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?
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.
<span class="btn" onclick="somefunction()">
<img style="cursor:pointer" title="Submit" alt="Submit" src="http://stackoverflow.com/imagesbutton.png?2012">
<div id="s" style=""></div>
</span>
<span onClick>example that you gave is going to make this a really tough problem to solve in the general case. In your<span onClick>example, I assume that typing stuff into the form and pressing <kbd>Enter</kbd> doesn't work, either. If the browser can't spot the submit button, I don't give your wrapper good odds...