views:

22

answers:

1

Hello everyone

My VB.NET code is supposed to execute third party Javascript code in an attempt to fill in and submit a form. This process consists of five steps, and I have been able to submit the form when all the steps are kept separate (i.e. behind 5 separate consequtive button clicks). Now, what I'd like to have is one button to handle all the five steps.

The problem is that the form originally only appears after calling "webbrowser.Navigate" command, which apparently modifies the page's HTML code. I seem to be unable to detect when Javascript has finished loading the new HTML in order to fill and submit the form. I have tried a timer control to wait for a certain HTML element ID to appear, but in vain.

This question has been asked before in different forms, but at least I could not find much help from the earlier answers:

http://stackoverflow.com/questions/1912678/invalidcastexception-with-webbrowser-isbusy-or-readystate-vb-net

http://stackoverflow.com/questions/1454451/detect-when-ajax-changes-html-in-a-div-in-webbrowser

http://www.techtalkz.com/vb-net/374234-vb-net-webbrowser-control-how-capture-javascript-events-statusbar-changed-mouseclick-etc.html

Please help me.

A: 

Well, this is the way it normally works in the software industry: Only after you've explained the problem to others, are you in a position to sufficiently understand it - and solve it yourself.

The problem was that I had not been using System.Windows.Forms.Timer() but another (less suitable) timer class for tracking changes in the HTML code. This was the reason why Application.DoEvents() did not work. With System.Windows.Forms.Timer() I was able to create a Timer.Tick event that keeps track of the phase of the form submittal (1-5 in my example) and attempts to execute the required Javascript commands in a Try-Catch construction. If an exception is caught, Application.DoEvents() is executed instead, and the timer ensures that the same commands are attempted to be executed shortly again.

This seems to work for me.

Aero