我在VBA中时这样做的。
[local]2[/local]
Private Sub CommandButton1_Click()
Dim x As Integer
Dim Uname As String
Dim Upw As String
x = Sheets("sheet2").Range("A65536").End(3).Row
For i = 1 To x
With CreateObject("InternetExplorer.Application")
Uname = Sheets("sheet2").Cells(i, 1).Value
Upw = Sheets("sheet2").Cells(i, 2).Value
.Visible = True
.Navigate "http://172.16.1.242:7001/kaoshi.do"
Do Until .Readystate = 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:02"))
If .locationname = "安全监督与管理系统" Then
.Document.Forms(0).All.tags("img")(1).Click
Else
'.Document.Forms(0).All("username").Value = Uname
'.Document.Forms(0).All("password").Value = Upw
'.Document.Forms(0).All("login_img").Click
.Document.Forms(0).All("j_username").Value = Uname
.Document.Forms(0).All("j_password").Value = Upw
.Document.Forms(0).All.tags("input")(4).Click
.Document.Forms(0).All.tags("img")(5).Click
Application.Wait (Now + TimeValue("0:00:02"))
.Document.Forms(0).getelementsbytagname("primarykey").Click
.Document.Forms(0).All.tags("button")(2).Click
End If
Application.Wait (Now + TimeValue("0:00:05"))
.Quit
End With
Next
MsgBox "Ok"
End Sub
红色代码前是自动登录代码,已经完成。
登录后进入选择考试界面。
这个是源代码:
<HTML>
<HEAD>
<TITLE>考试计划基本信息表查询</TITLE>
<link rel="stylesheet" type="text/css" href="http://172.16.1.242:7001/skins/default/css/skin.css">
<link rel="stylesheet" type="text/css" href="/css/saf/ks/DA_comm.css">
<script language="javascript" src="http://172.16.1.242:7001/skins/default/js/flexgrid.js"></script>
<link rel="stylesheet" type="text/css" href="http://172.16.1.242:7001/skins/default/css/flexgrid.css">
<link rel="stylesheet" type="text/css" href="http://172.16.1.242:7001/skins/default/css/date.css">
<script language="javascript" src="http://172.16.1.242:7001/skins/default/js/calendar.js"></script>
<script language="javascript" src="/js/saf/ks/zxks/DA_Service.js" /></script>
<script language="javascript" src="/js/saf/ks/DA_publicfunction.js" /></script>
</HEAD>
<BODY topmargin="10px">
<div class="examtitle1"><img src="/images/saf/ks/title.gif"> 在线考试</div>
<TABLE class="tblList" id="tblMain"
width="100%" height="" cellpadding="0">
<TBODY>
<TR>
<TD vAlign="top" height="15px">
<TABLE width="100%" background="http://172.16.1.242:7001/skins/default/images/title_bgright.gif" cellpadding="0" cellspacing="0">
<TR>
<TD vAlign="bottom">
<TABLE class="tblHead" id="tblHead" background="http://172.16.1.242:7001/skins/default/images/title_bgright.gif" cellpadding="0">
<TR>
<TD><IMG src="http://172.16.1.242:7001/skins/default/images/title_left.gif" border="0"></TD>
<TD class="tdHeadlineText" id="tdHeadlineText" vAlign="bottom" background="http://172.16.1.242:7001/skins/default/images/title_bgleft.gif" nowrap>
</TD>
<TD><IMG src="http://172.16.1.242:7001/skins/default/images/title_right.gif" border="0"></TD>
</TR>
</TABLE></TD>
<TD style="TEXT-ALIGN: right" width="56%" nowrap id="TagContainerButtonArea1">
</TD>
</TR>
</TABLE>
<TABLE class="tblHeadline" id="tblHeadline" width="100%" background="http://172.16.1.242:7001/skins/default/images/skin_top_bg.gif" cellpadding="0">
<TR>
<TD class="tdHeadline"><IMG src="http://172.16.1.242:7001/skins/default/images/skin_top_left.gif"></TD>
<TD class="tdHeadline" vAlign="bottom" align="right"><IMG src="http://172.16.1.242:7001/skins/default/images/skin_top_right.gif" border="0"></TD>
</TR>
</TABLE>
</TD></TR>
<TR><TD>
<TABLE class="tblWorkArea" id="tblWorkArea" width="100%" height="100%" cellpadding="0">
<TR>
<TD class="tdMargin3px" background="http://172.16.1.242:7001/skins/default/images/skin_right.gif"></TD>
<TD class="tdWorkArea" id="tdWorkArea" valign="top" height="100%">
<form name="frmList" method="post" action="personexamplanquery_page_init.cmd?operatetype=current&clear=true&flag=1&examno=1201194261000001"><div><input type="hidden" name="org.sotower.web.taglib.util.token" value="7eb46425ebb2be3d09fe4a39815dd841"></div><input type="hidden" name="sysFunctionId" value="">
<table id="tblSearch">
<tr>
<td>考试名称:<input type="text" name="titleSearch" maxlength="100" size="12" value="" class="searchText"></td>
<td>考试地点:<input type="text" name="addressSearch" maxlength="100" size="12" value="" class="searchText"></td>
<td colspan="2">考试开始时间:<input size="16" class="date_input" value="" onchange="start_datedd.setHidDateValInCalendar('yyyy-MM-dd');" readonly="readonly" ondblclick="javascript:this.value='';"name="start_dateSearch"><button
hideFocus="true" UNSELECTABLE="on" title="日历" class="date_button" onclick="start_datedd.showDate();">6</button><div id="start_datedd" class="date" style="display:none;overflow:hidden;position:absolute;z-index:10;" onpropertychange="start_datedd.doUpDown();"><div><table border="0" cellpadding="1" cellspacing="1" class="date_table"><tr><td>
<div class="dateadjust" style="width:80px;"><div style="position:relative;left:47;top:2;">
<button style="left:9;top:-1;height:10;" hideFocus="true" onclick="start_datedd._uper(this);start_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);"
onmousedown="start_datedd._conti_uper(this);start_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);" onmouseout="start_datedd._stop_inch();" onmouseup="start_datedd._stop_inch();">5</button>
<button style="left:9;top: 8;height:10;" hideFocus="true" onclick="start_datedd._downer(this);start_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);"
onmousedown="start_datedd._conti_downer(this);" onmouseout="start_datedd._stop_inch();" onmouseup="start_datedd._stop_inch();">6</button></div>
<input type=text style="padding-top:2;position:relative;left:2;" value="2012" onblur="start_datedd.doYearBlur(this);" conf="1,1900,2100,"></div></td>
<td><span
class="month" style="height:19;left:3;"><select size="1" onchange="start_datedd.changeYearAndMonth(null,this.options[this.selectedIndex].value)">
<option value="1">一月</option>
<option value="2">二月</option>
<option value="3">三月</option>
<option value="4">四月</option>
<option value="5">五月</option>
<option value="6">六月</option>
<option value="7">七月</option>
<option value="8">八月</option>
<option value="9">九月</option>
<option value="10"selected>十月</option>
<option value="11">十一月</option>
<option value="12">十二月</option>
</select></span></td></tr></table></div>
<div align=center></div>
<iframe frameborder=0 style="width:100%;height:103%;top:0;left:0;position:absolute;z-index:-1;"></iframe></div>
<script language="javascript">var start_datedd=new Calendar("start_datedd"); start_datedd.init("start_datedd",2012,10,9,14,47,8,"yyyy-MM-dd","yyyy-MM-dd"); </script>
至 <input size="16" class="date_input" value="" onchange="end_datedd.setHidDateValInCalendar('yyyy-MM-dd');" readonly="readonly" ondblclick="javascript:this.value='';"name="end_dateSearch"><button
hideFocus="true" UNSELECTABLE="on" title="日历" class="date_button" onclick="end_datedd.showDate();">6</button><div id="end_datedd" class="date" style="display:none;overflow:hidden;position:absolute;z-index:10;" onpropertychange="end_datedd.doUpDown();"><div><table border="0" cellpadding="1" cellspacing="1" class="date_table"><tr><td>
<div class="dateadjust" style="width:80px;"><div style="position:relative;left:47;top:2;">
<button style="left:9;top:-1;height:10;" hideFocus="true" onclick="end_datedd._uper(this);end_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);"
onmousedown="end_datedd._conti_uper(this);end_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);" onmouseout="end_datedd._stop_inch();" onmouseup="end_datedd._stop_inch();">5</button>
<button style="left:9;top: 8;height:10;" hideFocus="true" onclick="end_datedd._downer(this);end_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);"
onmousedown="end_datedd._conti_downer(this);" onmouseout="end_datedd._stop_inch();" onmouseup="end_datedd._stop_inch();">6</button></div>
<input type=text style="padding-top:2;position:relative;left:2;" value="2012" onblur="end_datedd.doYearBlur(this);" conf="1,1900,2100,"></div></td>
<td><span
class="month" style="height:19;left:3;"><select size="1" onchange="end_datedd.changeYearAndMonth(null,this.options[this.selectedIndex].value)">
<option value="1">一月</option>
<option value="2">二月</option>
<option value="3">三月</option>
<option value="4">四月</option>
<option value="5">五月</option>
<option value="6">六月</option>
<option value="7">七月</option>
<option value="8">八月</option>
<option value="9">九月</option>
<option value="10"selected>十月</option>
<option value="11">十一月</option>
<option value="12">十二月</option>
</select></span></td></tr></table></div>
<div align=center></div>
<iframe frameborder=0 style="width:100%;height:103%;top:0;left:0;position:absolute;z-index:-1;"></iframe></div>
<script language="javascript">var end_datedd=new Calendar("end_datedd"); end_datedd.init("end_datedd",2012,10,9,14,47,8,"yyyy-MM-dd","yyyy-MM-dd"); </script>
</td>
<td><input name="chaxun" type="image" src="http://172.16.1.242:7001/skins/default/images/search.gif" onClick="javascript:if(!checkSearch()) return false;;this.form.action='personexamplanquery_page_init.cmd?operatetype=current&clear=true&flag=1&examno=1201194261000001';document.all('org.sotower.web.taglib.util.GRIDINFOPRIMARY').value=null;document.all('org.sotower.web.taglib.util.RESETPAGEINDEX').value='true'" style="cursor: hand;"></td>
</tr><input type="hidden" name="org.sotower.web.taglib.util.SEARCHINFOCOLUMNS" value="titleSearch:DA_EXAMPLAN.TITLE:java.lang.String:=:false:false:;addressSearch:DA_EXAMPLAN.ADDRESS:java.lang.String:=:false:false:;start_dateSearch:DA_EXAMPLAN.START_DATE:java.lang.String:=:false:false:;end_dateSearch:DA_EXAMPLAN.END_DATE:java.lang.String:=:false:false:">
</table>
<script language="javascript">
var grid = new GRID();
var grid_jsonstr={"ColumnNames":["primaryKey","mainplan_id","planlevel","title","address"],"GRIDINFO":{"increaseIndex":"false","height":"222","hidden":[{"value":"","name":"org.sotower.web.taglib.util.GRIDINFOSORTTYPE"},{"value":"","name":"org.sotower.web.taglib.util.GRIDINFOSORTNAME"},{"value":"","name":"org.sotower.web.taglib.util.GRIDINFOPRIMARY"},{"value":"DA_EXAMPLAN.PLAN_ID;DA_EXAMPLAN.MAINPLAN_ID;DA_EXAMPLAN.PLANLEVEL;DA_EXAMPLAN.TITLE;DA_EXAMPLAN.ADDRESS","name":"org.sotower.web.taglib.util.GRIDINFOCOLUMNS"}],"isWrap":"false","hasLeft":"true","name":"grid","hasSum":"false"},"TabHead":{"rows":[{"cols":[{"width":"40","text":"选择","sortName":"DA_EXAMPLAN.PLAN_ID","style":"","sortType":"ASC","enableCheckAll":"true","format":"","canSort":"false"},{"width":"100","text":"主计划ID","sortName":"DA_EXAMPLAN.MAINPLAN_ID","style":"display:none","sortType":"ASC","enableCheckAll":"false","canSort":"true"},{"width":"100","text":"补考级别","sortName":"DA_EXAMPLAN.PLANLEVEL","style":"display:none","sortType":"ASC","enableCheckAll":"false","canSort":"true"},{"width":"100%","text":"考试名称","sortName":"DA_EXAMPLAN.TITLE","style":"text-align:left;","sortType":"ASC","enableCheckAll":"false","canSort":"true"},{"width":"150","text":"考试地点","sortName":"DA_EXAMPLAN.ADDRESS","style":"text-align:left;","sortType":"ASC","enableCheckAll":"false","canSort":"true"}]}]},"TabSum":{"rows":[{"cols":[{"text":"","width":"40"},{"text":"","width":"100","style":"display:none"},{"text":"","width":"100","style":"display:none"},{"text":"","width":"100%","style":"text-align:left;"},{"text":"","width":"150","style":"text-align:left;"}]}]},"TabTi":{"rows":[{"cols":[{"width":"40","eventString":"","coltype":"checkbox","disabled":"false","name":"primaryKey"},{"value":"","width":"100","eventString":"","coltype":"flex","style":"display:none"},{"value":"","width":"100","eventString":"","coltype":"flex","style":"display:none"},{"value":"","width":"100%","eventString":"","coltype":"flex","style":"text-align:left;"},{"value":"","width":"150","eventString":"","coltype":"flex","style":"text-align:left;"}]},{"cols":[{"value":"2c9081203991d585013a43236e8c09c9","checked":""},{"value":"2c9081203991d585013a43236e8c09c9","title":"2c9081203991d585013a43236e8c09c9"},{"value":"0","title":"0"},{"value":"安规测试1","title":"安规测试1"},{"value":"","title":""}]}]}};
grid.outHtml(grid_jsonstr,"http://172.16.1.242:7001/skins/default/js","grid");
grid.setSubmit(false);
function showGrid(){
this.init("grid");
}
grid.show = showGrid;
</script>
<table border="0" cellpadding="0" cellspacing="1" class="datactrl"><tr>
<td><input type="button" value="ç" title="上一页" hidefocus="true"></td>
<td><input type="button" value="è" title="下一页" hidefocus="true"></td>
<td style="font-size:9pt;border:0px;">共 1 页 第 1 页 共 1 条,从 1 条到 1 条</td>
</tr>
</table>
<input type="hidden" name="org.sotower.web.taglib.util.PAGEPOLITPAGESIZE" value="10">
<input type="hidden" name="org.sotower.web.taglib.util.PAGEPOLITCURRENTPAGEINDEX" value="1">
<input type="hidden" name="org.sotower.web.taglib.util.RESETPAGEINDEX" value="false">
</form>
</TD>
<TD class="tdMargin3px" background="http://172.16.1.242:7001/skins/default/images/skin_left.gif"></TD></TR></TABLE>
</TD></TR>
<TR><TD height=5>
<TABLE class="tblFoot" id="tblFoot" width="100%" background="http://172.16.1.242:7001/skins/default/images/skin_bottom_bg.gif" cellpadding="0">
<TR>
<TD class="tdFootLeft"><IMG src="http://172.16.1.242:7001/skins/default/images/skin_bottom_left.gif"></TD>
<TD class="tdFootRight"><IMG src="http://172.16.1.242:7001/skins/default/images/skin_bottom_right.gif"></TD>
</TR>
</TABLE></TD>
</TR>
</TABLE>
<script language="javascript">
var TagContainerButtonArea1=document.all("TagContainerButtonArea1");
if(TagContainerButtonArea1!=null && TagContainerButtonArea1.tagName=="TD")
TagContainerButtonArea1.innerHTML='<button
onclick="forSimpleDetail()" onmouseover="this.className=\'advbutton-over\';" onmouseout="this.className=\'advbutton\';" class="advbutton">详细信息</button> <button
onclick="checkIp()" onmouseover="this.className=\'advbutton-over\';" onmouseout="this.className=\'advbutton\';" class="advbutton">检验IP地址</button> <button
onclick="startExam()" onmouseover="this.className=\'advbutton-over\';" onmouseout="this.className=\'advbutton\';" class="advbutton">进入考试</button> ';
</script>
<script language="javascript">
grid.show();
function validateDate(){
var queryDateStart = document.getElementById("start_dateSearch").value;
var queryDateEnd = document.getElementById("end_dateSearch").value;
if(queryDateStart!="" && queryDateEnd!="" && queryDateStart>queryDateEnd){
alert("查询结束时间不能小于查询起始时间!");
return false;
}
return true;
}
//监听回车事件
function document.onkeydown()
{
if(event.keyCode == "13")
{
return checkSearch();
}
}
//检验查询条件
function checkSearch()
{
var value = document.getElementById("titleSearch").value;
var value1 = document.getElementById("addressSearch").value;
if( CheckSearch(value) || CheckSearch(value1))
{
return false;
}
if(!validateDate())
{
return false;
}
return true;
}
function forSimpleDetail(){
if(!getSelect()) return;
var line = grid.getCheckLineNo();
var primaryKey=grid.getCellValue(line, 1);
window.open ('daexamplan.cmd?method=simpleDetail&primaryKey='+primaryKey+'&operatetype=current', '', 'height=400, width=600, top=10, left=60, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no');
}
function startExam(){
if(!getSelect()) return;
if(!window.confirm("您确定要进入考试吗?")){
return;
}
var line = grid.getCheckLineNo();
var planId=grid.getCellValue(line, 1);
var url = "examonline.cmd?method=examStart&examPlanId="+planId+"&wstime="+(new Date()).valueOf();
window.showModalDialog(url,window,"dialogTop:0;dialogWidth:"+(window.screen.availWidth)+"px;DialogHeight="+(window.screen.availHeight)+"px;help=0;center=1;status:no;scroll=1");
window.location = window.location;
}
function checkIp()
{
if(!getSelect()) return;
var line = grid.getCheckLineNo();
var planId=grid.getCellValue(line, 1);
var service = new Service();
service.serviceUrl = "/examonline.cmd";
service.serviceParam = "method=checkIp&planId="+planId;
var result = service.send(planId);
if(result == "1")
{
alert("您的IP地址可以参加考试!");
}
else
{
alert("你的IP地址不合法,不能参加考试!请换台机器或联系管理员!");
}
}
function viewExam(){
if(!getSelect()) return;
var line = grid.getCheckLineNo();
var planId=grid.getCellValue(line, 1);
if(grid.getCellValue(line, 7) == "未阅卷")
{
alert("试卷未批阅,不能浏览!");
return;
}
var url ="/dayj.cmd?method=examCS&examPlanId="+planId+"&toPage=own"+"&wstime="+(new Date()).valueOf();
window.showModalDialog(url,window,"dialogTop:0;dialogWidth:"+(window.screen.availWidth)+"px;DialogHeight="+(window.screen.availHeight)+"px;help=0;center=1;status:no;scroll=1");
}
function forDetail(){
if(!getSelect()) return;
document.forms[0].action ="daexamplan.cmd?method=detail";
document.forms[0].submit();
}
function forDelete(){
if(!getDelete()) return;
document.forms[0].action ="daexamplan.cmd?method=delete";
document.forms[0].submit();
}
function getSelect(){
var sel=grid.getCheckLine();
if(sel==""){
alert("请选择一条记录!");
return false;
}
var obj=sel.split(",");
if(obj.length*1>1){
alert("请选择一条记录!");
return false;
}
return true;
}
function getDelete(){
var sel=grid.getCheckLine();
if(sel==""){
alert("请选择要删除的记录!");
return false;
}
if (!confirm("真的要删除选中的记录吗?此操作不能恢复!")) {
return false;
}
return true;
}
</script>
[
本帖最后由 享誉 于 2012-10-11 10:03 编辑 ]