使用Visual Basic自动登录表单

时间:2013-06-19 14:22:53

标签: vb.net

我需要使用Visual Basic 10.0为以下代码创建一个自动登录表单应用程序:

</script>
    <body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
        <table cellpadding="0" cellspacing="0" border="0" height="100%">
            <tr>
                <td rowspan="10" width="50%" height="100%" background="images/bg1222.jpg" style="background-position:right top; background-repeat:repeat-y"></td>
                <td rowspan="10" width="1" bgcolor="#000000"></td>
                <td valign="top">
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td width=100%>
                                <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="778" height="153">
                                    <param name="movie" value="images/hed2.swf">
                                    <param name="quality" value="high">
                                    <embed src="images/hed2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="778" height="153"></embed>
                                </object>
                            </td>
                        </tr>
                    </table>
                </td>
                <!--<td rowspan="10" width="0" bgcolor="#000000"></td>-->
                <td rowspan="10" width="50%" height="100%" background="images/bg1223.jpg" style="background-position:left top; background-repeat:repeat-y"></td>
            </tr>
            <tr>
                <td width="780" height="30" align="center" valign="bottom" background="images/footer.gif"></td>
            </tr>
            <tr>
                <td height="583" valign="top" style="background-repeat:repeat-y;" >
                <br><br><br><br><br><br><br>
              <center>
                    <form action="/cse/login/login1_check.jsp" name="first" method="post">
                        <table width="25%" height="90" border="0" class='formtable1'>
                            <caption align="top">
                              <strong> User Login </strong>
                              <br>
                            </caption>
                            <tr>
                            </tr>
                            <tr>
                                <td width="24%" height="32">
                                    <div align="right"> User ID: </div>
                                </td>
                                <td width="76%">
                                    <label>
                                        <input name="uid" type="text" >
                                    </label>
                                </td>
                            </tr>
                            <tr>
                                <td height="43">
                                    <div align="right"> Password: </div>
                                </td>
                                <td>
                                    <label>
                                        <input name="password" type="password" >
                                    </label>
                                </td>
                            </tr>
                        </table>
                        <input type="submit" name="sub" value="Login">
                    </form>
                 </center>`enter code here`

假设用户名为user,密码为pass

应该自动填写并在提交按钮中单击。 Visual Basic 10.0的代码是什么?

2 个答案:

答案 0 :(得分:1)

试试这个:

If Not String.IsNullOrEmpty(My.Settings.Username) And Not String.IsNullOrEmpty(My.Settings.Password) Then
        TxtUsername.Text = My.Settings.Username
        TxtPassword.Text = My.Settings.Password
End If

答案 1 :(得分:0)

您首先需要获取要与之交互的所有元素。如果他们有ID,您不需要搜索,只需获取元素:

Dim elem As HtmlElement = Webbrowser1.Document.GetElementById("myId")

如果没有,您需要搜索您的,例如:

Dim inputs As New List(Of HtmlElement)(a.Document.GetElementsByTagName("input"))

For Each elem As HtmlElement In inputs
    If elem.GetAttribute("name").Equals("uid") Then
        '...
    End If
Next

设置输入值:

elem.SetAttributte("value", passwordVar)

单击可点击元素(例如提交输入):

elem.InvokeMember("submit")

或者:

elem.InvokeMember("click")