Writing VB6 code to get a WebBrowser control to navigate Java Scripted HTML

PeterFrb used Ask the Experts™
We use Quantisense at work, an online database designer.  The interface is run entirely online, and the process of running queries consists of going through menus and pressing online buttons to perform various functions.  I would like to automate some of these processes using VB code, and my question is how to do the equivalent of pressing online buttons that run java scripts using a web browser control within VB.  I have examined the HTML source and can determine the button names, but I'm basically left to decipher html such as the following, which flashes the words "Re-run report" when the cursor moves over the button, to figure out what routine gets run when the user pushes the button with their mouse:

<TD ID=mnT NAME=mnT>Re-run report</TD><TD ID=mnS NAME=mnS>&nbsp;&nbsp;&nbsp;<TD ID=mnE NAME=mnE></TD></TR><TR ID="mb2o11" B=mb2 SB=0 ONMOUSEOVER="OMS(this);" ONMOUSEOUT="OOS(this);" ONCLICK="OCS(this);" T="0" U="Main.aspx?evt=4047&src=Main.aspx.report.frame.rb.4047&fresh=false&rePrompt=false" A=1 E=1 H=0 ><TD ID=mnI NAME=mnI></TD>

I have a fair amount of experience writing VB6 code for the web browser control to perfom sequential processes, such as downloading emails and images; but these transactions are straightforward compared to writing code to duplicate the act of pushing a button that executes a java script.  Any insight would be helpful.

Thanks, Peter Ferber
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
A lot of what you can do with hte WebBrowser control is similar to Javascript. It has an almost identical object model, so if you can think of how you'd do it in javascript in your page, that will give you a good hint as to how to do it in VB6 using the WebBrowser.

For example, to submit a form:


Also, since VB's intellisense doesn't get past the "Document" object, run your project, and breakpoint at some reasonable part of your code. From there, the Watch window will be *exceedingly* useful in looking at the various objects on the page.

I'll do some poking around and see if it's easy to cause a button's onclick to be executed.
Yes. You can do it. An example would be:


Other events such as onchange, onblur, ondblclick etc. may also be called in this way:


A word of warning! Any object that does *not* have the event defined, like, say, a button that doesn't have an onclick event, will cause a runtime error in VB if you try and call it using it's "onsomething" name. E.g. if the MyButtonName button never had an onclick defined, calling the onclick method in the webbrowser control could raise an error.

So, be sure you're button really has an onclick event :P
PeterFrbData anslyst, tableau visualization developer, vb certified


Looks great!  I have a bit on my plate at this moment; but if this checks out, as I assume it will, I'll give you credit for this answer by Friday, midafternoon.  
Thanks for the quick return on my question.  Much obliged, as always,

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial