网页按钮的点击问题
内网的电子考勤系统,要求每天上班前登录一下,点个签到,很是烦人,自己想弄个自动签到系统,但是本人很菜,出了点问题:
[code=VB][/code]Private Sub Command1_Click()
Dim objDoc
On Error Resume Next
Set objDoc = WebBrowser1.Document
For I = 1 To objDoc.All.Length - 1
If objDoc.All(I).Name = "TextBox1" Then
objDoc.All(I).Value = Text1.Text
ElseIf objDoc.All(I).Name = "TextBox2" Then
objDoc.All(I).Value = Text2.Text
objDoc.All(I).focus
sendkey "{enter}"
' ElseIf objDoc.All(I).Name = "Button1" Then
' objDoc.All(I).Click
End If
Next
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim objDoc
On Error Resume Next
Set objDoc = WebBrowser1.Document
For I = 1 To objDoc.All.Length - 1
If objDoc.All(I).Name = "TextBox1" Then
objDoc.All(I).Value = Text1.Text
ElseIf objDoc.All(I).Name = "TextBox2" Then
objDoc.All(I).Value = Text2.Text
objDoc.All(I).focus
sendkey "{enter}"
' ElseIf objDoc.All(I).Name = "Button1" Then
' objDoc.All(I).Click
End If
Next
End Sub
我有两个问题出来了,一,使用' ElseIf objDoc.All(I).Name = "Button1" Then
' objDoc.All(I).Click,它是死活它不点击或者说他有出现别的问题没有反应,换别的属性也没用,只好用sendkeys了,用了sendkeys第二个问题出来了,那就是我用命令按钮调试它是可以登录上去的,但是使用WebBrowser1_DocumentComplete一样的语句它只是填写的用户名和密码,它不登录!很郁闷
另把网面的源码也贴上来,大家看下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
考勤登记系统
</title>
<style type="text/css">
.style1
{
font-family:Tahoma,Verdana,"宋体"; font-size: 12px;
}
.button1 { border: #999999; border-style: double; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; font-family:Tahoma,Verdana,"宋体"; font-size: 12px; line-height: 15px;COLOR: #000000;}
</style>
</head>
<body>
<form name="form1" method="post" action="login.aspx" id="form1">
<div>
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTU2MzQ1NzIyMGRkrPaC46Wfk8/FoaAyxiiIQBIj5tU=" />
</div>
<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>
<script src="/WebResource.axd?d=bLlVDp3ZWxEa917bDqzKpg2&t=633759254897031250" type="text/javascript"></script>
<script src="/WebResource.axd?d=Sqdk0DMjrjozlEha79VLiQ2&t=633759254897031250" type="text/javascript"></script>
<div>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" style="z-index: 100; left: 0px; position: absolute; top: 0px">
<tr>
<td height="700" align="center" valign="middle" bgcolor="#0a68af" >
<input type="submit" name="Button1" value="请登录" id="Button1" tabindex="2" style="left: 7px;
position: relative; top: 193px" />
<table width="650" height="410" border="0" align="center" cellpadding="0" cellspacing="0" background="Images/login2.jpg" >?????点击不是点这儿吧?
<tbody>
<tr>
<td align="center" style="width: 650px; height: 310px;">
<input name="TextBox2" type="password" id="TextBox2" tabindex="12" class="button1" style="width:130px;left: 337px;
position: relative; top: -65px; z-index: 100;" />
<input name="TextBox1" type="text" id="TextBox1" tabindex="11" class="button1" style="width:142px;position: relative; left: -19px; top: -64px; z-index: 100;" />
<span id="Label1" class="style1" style="display:inline-block;color:Red;width:191px;position: relative; left: -326px; top: -25px; z-index: 100;"></span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</div>
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAK4uZf2BwKM54rGBgLs0fbZDALs0bLrBoZyY2mBsZAcAyCoHpIrpaOT2D/l" />
</div>
<script type="text/javascript">
<!--
WebForm_AutoFocus('TextBox1');// -->
</script>
</form>
</body>
</html>
[解决办法]
Private Sub Command1_Click()
WebBrowser1.Document.getelementbyid("TextBox2").Value = Text2.Text
WebBrowser1.Document.getelementbyid("TextBox1").Value = Text1.Text
WebBrowser1.Document.getelementbyid("Button1").Click
End Sub
这样试试看,不保证成功,因为我无法测试……
[解决办法]
太复杂,看不清楚。
直接网站上login下麻烦么?