Link to home
Start Free TrialLog in
Avatar of creas002
creas002

asked on

WebBrowser1.document Click button from VB - Click not working

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>
Avatar of creas002
creas002

ASKER

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

<INPUT TYPE="submit" NAME="BUTTON_INPUT"
value="Restart Cable Modem">
Avatar of amit_g
Use

WebBrowser1.document.forms(0).elements("BUTTON_INPUT").click
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

(...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")
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial