添加WebBrowser1,Command1,Timer1Option ExplicitDim isDone As BooleanPrivate Sub Command1_Click() WebBrowser1.Navigate "http://mail.126.com" isDone = False Timer1.Interval = 3000 End SubPrivate Sub Timer1_Timer() If InStr(1, WebBrowser1.Document.body.outerText, "密码输入不正确!") <> 0 Then MsgBox "密码错误" Timer1.Enabled = False End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) If Not isDone Then With WebBrowser1.Document .getElementByID("iptUser").SetAttribute "value", "[email protected]" .getElementByID("iptPwd").SetAttribute "value", "123456" .getElementByID("iptPwd").focus SendKeys "{enter}" End With isDone = True Else Timer1.Enabled = True End If End Sub
WebBrowser1.Navigate "http://mail.126.com"
isDone = False
Timer1.Interval = 3000
End SubPrivate Sub Timer1_Timer()
If InStr(1, WebBrowser1.Document.body.outerText, "密码输入不正确!") <> 0 Then MsgBox "密码错误"
Timer1.Enabled = False
End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If Not isDone Then
With WebBrowser1.Document
.getElementByID("iptUser").SetAttribute "value", "[email protected]"
.getElementByID("iptPwd").SetAttribute "value", "123456"
.getElementByID("iptPwd").focus
SendKeys "{enter}"
End With
isDone = True
Else
Timer1.Enabled = True
End If
End Sub