vb中自动填写表单WebBrowser的问题
相关网页代码:
用户名: <input name= 'UserName ' type= 'text ' id= 'UserName '>
密 码: <input name= 'UserPassword ' type= 'password ' id= 'Password '>
验证码: </td> <td height= '25 '> <input name= 'CheckCode ' type= 'text ' id= 'CheckCode ' size= '6 ' maxlength= '6 '> <a href= 'javascript:refreshimg() ' title= '看不清楚,换个图片 '> <img id= 'checkcode ' src= 'inc/checkcode.asp ' style= 'border: 1px solid #ffffff '> </a> </td>
<input name= 'Login ' type= 'submit ' id= 'Login ' value= ' 登 录 '>
<script language=javascript>
function refreshimg(){document.all.checkcode.src= 'inc/checkcode.asp ';}
function CheckLoginForm(){
if(document.UserLogin.UserName.value== ' '){
alert( '请输入用户名! ');
document.UserLogin.UserName.focus();
return false;
}
if(document.UserLogin.Password.value == ' '){
alert( '请输入密码! ');
document.UserLogin.Password.focus();
return false;
}
if(document.UserLogin.CheckCode.value == ' '){
alert( '请输入验证码! ');
document.UserLogin.CheckCode.focus();
return false;
}
}
</script>
我的VB代码:
Private Sub kxedu_DocumentComplete(ByVal pDisp As Object, URL As Variant)
web.Document.Forms(0).UserLogin.UserName.Value = "msn2005 "
web.Document.Forms(0).UserLogin.Password.Value = "724864 "
web.document.Forms(0).UserLogin.CheckCode.Value=???
web.Document.Forms(0).Login.Click
End Sub
我这种方法简直没用,后来参考其它资料,改为如下:
Dim vDoc, vTag
Dim i As Integer
Dim h As Integer
Set vDoc = kxedu.Document
For i = 0 To vDoc.All.length - 1
Set vTag = vDoc.All(i)
Select Case vTag.tagname
Case "input "
Select Case vTag.Name
Case "username "
vTag.Value = "msn2005 "
Case "password "
vTag.Value = "123456 "
End Select
End Select
Next i
仍然无法填写用户名和密码,更别说验证码和登录了。不知如何办才行?
[解决办法]
真是个直心眼的兄弟呀……
你再前面加个Lcase()或者Ucase()不行吗……
另外密码的name是UserPassword好不好……
For i = 0 To vDoc.All.length - 1
Set vTag = vDoc.All(i)
Select Case LCase(vTag.tagname)
Case "input "
Select Case LCase(vTag.Name)
Case "username "
vTag.Value = "msn2005 "
Case "userpassword "
vTag.Value = "123456 "
End Select
End Select
Next i
[解决办法]
Dim vDoc, vTag
Dim i As Integer
Dim h As Integer
Set vDoc = kxedu.Document
For i = 0 To vDoc.All.length - 1
If UCase(vDoc.All(i).tagName) = "INPUT " Then
Set vTag = vDoc.All(i)
Select Case vTag.Name
Case "username "
vTag.Value = "msn2005 "
Case "userpassword "
vTag.Value = "123456 "
End Select
Next i
[解决办法]
因为上面的程序没有输入正确的验证码,所以最后一步提交是没 用的,固没有任何提示,最近我也是在搞类似的程序,验证码问题还没解决啊,也希望各为高手们再想想,我觉得这个随机的验证码好象是程序输不了的,而要人手啊,所以只要完成输入用户名和密码,验证码还要人手根据实际输入,这样程序才能完成登陆啊
[解决办法]
web.Document.Forms(0).Login.Click
===============
对提交按钮,不用click方法,用submit
或先要让提交按钮获得焦点,如
web.Document.Forms(0).Login.setfocus
web.Document.Forms(0).Login.Click