VB填充IE上的輸入框并提交
假設(shè)登錄頁面的HTML代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>testPage</title>
</head>
<body>
<FORM name=chh method = "POST" action = "login.asp">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="31%" align="center">用戶:</td>
<td width="69%" align="left">
<input name="LoginName" type="text" id="LoginName" size="12">
</td>
</tr>
<tr>
<td width="31%" align="center">密碼:</td>
<td width="69%" align="left">
<input name="LoginPassword" type="password" id="LoginPassword" size="12">
</td>
</tr>
</table>
<input type = "submit" id = "clickme" value = "提交">
</FORM>
</body>
</html>
很簡單的頁面,在上面有一個登錄的Form,一個用戶名輸入框LoginName,一個密碼輸入框LoginPassword和一個提交按鈕clickme
然后用IE打開這個頁面,注意頁面的title設(shè)置為testPage。
然后打開VB,在工程中引用Microsoft internet controls:
Private Sub Command1_Click()
Dim IEList As New ShellWindows
Dim browser
Dim Doc
On Error Resume Next
'遍歷當前地瀏覽器窗口
For Each browser In IEList
'找到需要地IE窗口
If browser.Document.Title = "testPage" Then
'獲得瀏覽器地文檔對象
Set Doc = browser.Document
'填寫用戶名字段
Doc.body.All("LoginName").Value = "eddie"
'填寫密碼字段
Doc.body.All("LoginPassword").Value = "123456"
'提交
Doc.body.All("clickme").Click
End If
Next
End Sub
新聞熱點
疑難解答