We help IT Professionals succeed at work.

WebBrowser1.document Click button from VB - Click not working

9,074 Views
Last Modified: 2013-11-26
I have read many posts and solutions but have not been successful at making my VB app click a button on an HTML page that it loads.  

Here is the VB Code:

Sub main()

    WebBrowser1.navigate "http://192.168.100.1/configdata.html"
   
    DoEvents: DoEvents: DoEvents
   
    Do While WebBrowser1.Busy
      DoEvents
    Loop
   
    Set doc = WebBrowser1.document
    DoEvents
   
    Do While WebBrowser1.Busy
    DoEvents
    Loop
         
    ' WebBrowser1.document.Forms(0).submit
       
    WebBrowser1.document.body.All.Item(0).Click  ' Does not error but does not click the button

End Sub

Private Sub Form_Load()
  Call main
  RM.Show
End Sub

Here is the HTML Page

<HTML>
<HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="Wed, 30 Apr 1975 02:00:00 GMT
">
<TITLE>Confirm</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
<!-- Begin
function prompt_msg() {
agree= window.confirm("This action requires re-initialization of the cable modem.  This process could take from 5 to 30 minutes.  Do you want to proceed?");
if (agree == false)
{
   return "Cancel Reset";
}
else
{
   return "Reset All Defaults";
}
}
// END-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000"
            LINK="#485A91"
VLINK="#7B2939" ALINK="#7B2939"

<TABLE border="0" cellspacing="0" cellpadding="0">
<TR><CENTER>
    <TABLE width="85%" border="0" cellspacing="0" cellpadding="5">
    <TR>
    <TH BGCOLOR="#000000">

    <FONT COLOR="White" FACE="Arial,Helvetica">
    Configuration Manager
    </FONT></TH>
    </TR></TABLE>
</CENTER></TR>

<TR><CENTER>
    <TABLE width="85%" border="0" cellspacing="0" cellpadding="5">
    <TR>


<TH BGCOLOR="#CCCC99">

<A HREF="/startup.html" TARGET="_top" STYLE="TEXT-DECORATION:none">
<FONT COLOR="#485A91" FACE="Arial,Helvetica">
Status</FONT></A></TH>


<TH BGCOLOR="#CCCC99">
<A HREF="/signal.html" TARGET="_top" STYLE="TEXT-DECORATION:none">
<FONT COLOR="#485A91" FACE="Arial,Helvetica">
Signal</FONT></A></TH>


<TH BGCOLOR="#CCCC99">
<A HREF="/address.html" TARGET="_top" STYLE="TEXT-DECORATION:none">
<FONT COLOR="#485A91" FACE="Arial,Helvetica">
Addresses</FONT></A></TH>


<TH BGCOLOR="#666600">
<A HREF="/config.html" TARGET="_top" STYLE="TEXT-DECORATION:none">
<FONT COLOR="White" FACE="Arial,Helvetica">
Configuration</FONT></A></TH>


<TH BGCOLOR="#CCCC99">
<A HREF="/logs.html" TARGET="_top" STYLE="TEXT-DECORATION:none">
<FONT COLOR="#485A91" FACE="Arial,Helvetica">
Logs</FONT></A></TH>


<TH BGCOLOR="#CCCC99">

<A HREF="/mainhelp.html" TARGET="_top" STYLE="TEXT-DECORATION:none">
<FONT COLOR="#485A91" FACE="Arial,Helvetica">
Help</FONT></A></TH>

</TR></TABLE></CENTER></TR>
<TABLE WIDTH="100%" BORDER=0 CELLSPACING=0 CELLPADDING=5
ALIGN="CENTER" BGCOLOR="#000000">
<TR>
<TD BGCOLOR="#FFFFFF">
This page provides information about the manually configurable settings of the Cable Modem.
</TD>
</TR>
</TABLE>
<IMG SRC="/line.gif" WIDTH="100%">
<P>
</P>
<FORM METHOD="POST" ACTION="http:/configdata.html">

<CENTER>
<TABLE ALIGN="center" CELLPADDING=8 CELLSPACING=0 BORDER=1>
<TR>
<TH BGCOLOR="#736B08"><FONT COLOR="#FFFFFF">
Configuration</FONT></TH>
</TR>
<TR>
<TD>Frequency Plan:
North American Standard/HRC/IRC
</TD>
</TR>
<TR>
<TD>Upstream Channel ID:
3
</TD>
</TR>
<TR>
<TD>Frequency (Hz):
609000000

</TD>
</TR>
<TR>
<TD>
DHCP Server Enabled<BR><SMALL>The SURFboard cable modem can be used as a gateway to the Internet by a maximum of 32 users on a Local Area Network (LAN).  When the Cable Modem is disconnected from the Internet, users on the LAN can be dynamically assigned IP Addresses by the Cable Modem DHCP Server.  These addresses are assigned from an address pool which begins with 192.168.100.11 and ends with 192.168.100.42.  Statically assigned IP addresses for other devices on the LAN should be chosen from outside of this range</SMALL></TD>
</TR>
<TR>
<TD>
<INPUT TYPE="submit" NAME="BUTTON_INPUT"
 value = "Reset All Defaults" onClick="this.value=prompt_msg()">

<BR><SMALL>
<STRONG>Note:</STRONG><BR>
Resetting the cable modem to its factory default configuration will
remove all stored parameters learned by the cable modem during prior
initializations.
The process to get back online from a factory default condition could take from
5 to 30 minutes.  Please reference the cable modem User Guide for details
on the power up sequence.
</SMALL>

</TD>
</TR>
</TABLE>
<P></P>
<INPUT TYPE="submit" NAME="BUTTON_INPUT"
value="Restart Cable Modem">
</CENTER>
</FORM>
<IMG SRC="/line.gif" WIDTH="100%">
<P>
</P>
<STRONG>
<CENTER>
<FONT FACE="Arial, Helvetica">
<P></P>
<P>
<A HREF="/startup.html" TARGET="_top">Status</A> |

<A HREF="/signal.html" TARGET="_top">Signal</A> |
<A HREF="/address.html" TARGET="_top">Addresses</A> |
<A HREF="/config.html" TARGET="_top">Configuration</A> |
<A HREF="/logs.html" TARGET="_top">Logs</A> |
<A HREF="/mainhelp.html" TARGET="_top">Help</A>
</P>
</FONT>
</CENTER>

</STRONG>
<TABLE BORDER=0 CELLSPACING=0 ALIGN="CENTER" BGCOLOR="#FFFFFF">
<TR>
<TD><CENTER><IMG SRC="/copyright.gif"></CENTER></TD>
</TR>
<TR>
<TD BGCOLOR="#FFFFFF">
<CENTER><SMALL><FONT COLOR="#000000" FACE="Arial , Helvetica">
<A HREF="/legal.html" TARGET="_top">
&copy Copyright 1997-2002</A>
</FONT></SMALL></CENTER></TD>
</TR>
</TABLE>
</BODY>
</HTML>
Comment
Watch Question

Author

Commented:
I forgot to mention... The button that I'm trying to click is

<INPUT TYPE="submit" NAME="BUTTON_INPUT"
value="Restart Cable Modem">
CERTIFIED EXPERT
Top Expert 2006

Commented:
Use

WebBrowser1.document.forms(0).elements("BUTTON_INPUT").click

Author

Commented:
The HTML code has more than 1 button labeled BUTTON_INPUT, however I did try your suggestion and received the following error:

Object doesn't support this property or method

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
(...I suck at HTML stuff...)

I have used this type of syntax with success in VB.Net 2005:

    WebBrowser1.Document.All("BUTTON_INPUT").InvokeMember("click")
CERTIFIED EXPERT
Top Expert 2006
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.