我正在使用HttpUnit来模拟设计成指定 url 的表单的提交按钮单击。(我正在使用http://stu21.kntu.ac.ir/Login.aspx
)。我使用如下代码来获取响应页面。
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest("http://stu21.kntu.ac.ir/Login.aspx");
WebResponse response = conversation.getResource(request);
WebForm loginForm = response.getForms()[0]; //Form has been got successfully
request = loginForm.getRequest();
request.setParameter("txtusername", "8810103" );
request.setParameter("txtpassword", "8810103" );
response = conversation.getResponse( request ); //error while getting the .js files
它成功获取表单,但是当我填写表单并想提交表单时,发生以下错误:
getSubframeResponse(WebWindow.java:183) 在 com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158) 在 com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:199) 在 com.meterware.httpunit.WebWindow .getSubframeResponse(WebWindow.java:183) 在 com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158) 在 com.meterware.httpunit.WebClient.getResponse(WebClient.java:122) 在 Main.main(Main. java:76) 线程“main”中的异常 com.meterware.httpunit.ScriptException: Script 'var shuffleArray = new Array(); //var 字段 = ""; shuffle = function (o) { //v1.0 java:183) 在 com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158) 在 com.meterware.httpunit.WebClient.getResponse(WebClient.java:122) 在 Main.main(Main.java:76) 异常在线程“主”com.meterware.httpunit.ScriptException:脚本'var shuffleArray = new Array(); //var 字段 = ""; shuffle = function (o) { //v1.0 java:183) 在 com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158) 在 com.meterware.httpunit.WebClient.getResponse(WebClient.java:122) 在 Main.main(Main.java:76) 异常在线程“主”com.meterware.httpunit.ScriptException:脚本'var shuffleArray = new Array(); //var 字段 = ""; shuffle = function (o) { //v1.0
for (var j, x, l = o.length; l; j = parseInt(Math.random() * l), x = o[--l], o[l] = o[j], o[j] = x); for (var H = 0; H < 10; H++) { shuffleArray[H] = o[H]; } return o; }
///////////////////////////键盘脚本函数 KeyPadInit() { alert("yes"); var 随机数;var myNumbers = new Array();
for (jj = 0; jj < 10; jj++) { randomnumber = Math.floor(Math.random() * 10); while (IsInArray(myNumbers, randomnumber) == 1) { randomnumber = Math.floor(Math.random() * 10); }; switch (jj) { case 0: document.getElementById('btnSeven0').value = randomnumber; break; case 1: document.getElementById('btnSeven1').value = randomnumber; break; case 2: document.getElementById('btnSeven2').value = randomnumber; break; case 3: document.getElementById('btnSeven3').value = randomnumber; break; case 4: document.getElementById('btnSeven4').value = randomnumber; break; case 5: document.getElementById('btnSeven5').value = randomnumber; break; case 6: document.getElementById('btnSeven6').value = randomnumber; break; case 7: document.getElementById('btnSeven7').value = randomnumber; break; case 8: document.getElementById('btnSeven8').value = randomnumber; break; case 9: document.getElementById('btnSeven9').value = randomnumber; break; } myNumbers[myNumbers.length] = randomnumber; }
}
函数 IsInArray(objArray, num) { for (i = 0; i <= objArray.length - 1; i++) { if (objArray[i] == num) 返回 1; } 返回 0; }
功能改变风格(objbtn,动作){
if (action == 'out') { objbtn.className = 'PadStyle'; } else if (action == 'over') { objbtn.className = 'PadStyleOver'; }
}
var inpId = new Array(); var shuffleArray = new Array();
// * ** * ** * ** * ** * ** * ** * ***计算输入框的数量* ** * ** * ** * ** * ** * ** * * * * ** * ***fillArray = function () { inpId.splice(0, inpId.length - 1); 变量 i = 0; var InputsId = document.getElementsByTagName("input"); for (var k = 0; k < InputsId.length; k++) { if ((InputsId[k].type == "text") || (InputsId[k].type == "password") || (InputsId [k].type == "checkbox") || (InputsId[k].type == "submit")) { if (!(InputsId[k].disabled)) { inpId[i++] = InputsId[k] ; } } } }
函数 AmountMaskE2(amount) { var i, j, mystring, flag;
if (amount == '') return ""; i = amount.length; mystring = ""; for (j = 0; j < i; j++) { if (amount.substring(j, j + 1) == ",") { flag = true; } } if (flag == true) { amount = DAmountMaskE(amount); } i = amount.length; if (i > 3) { for (j = i; j > 0; j = j - 3) { if (j > 3) { mystring = "," + amount.substring(j - 3, j) + mystring; } else { mystring = amount.substring(0, j) + mystring; } } return mystring; } else { return amount; }
}
函数 DAmountMaskE(amount) { var i, j, mystring, str; 我=数量.长度;我的字符串 = "";
for (j = i; j >= 0; j -= 1) { str = amount.substring(j, j - 1); if (str != ",") { mystring = str + mystring; } } return mystring; }' failed: org.mozilla.javascript.EvaluatorException: illegal character at
com.meterware.httpunit.javascript.ScriptingEngineImpl.handleScriptException(ScriptingEngineImpl.java:64) 在 com.meterware.httpunit.javascript.ScriptingEngineImpl.runScript(ScriptingEngineImpl.java:95) 在 com.meterware.httpunit.scripting.ScriptableDelegate.runScript( ScriptableDelegate.java:88) 在 com.meterware.httpunit.parsing.NekoDOMParser.runScript(NekoDOMParser.java:151) 在 com.meterware.httpunit.parsing.ScriptFilter.getTranslatedScript(ScriptFilter.java:150) 在 com.meterware.httpunit .parsing.ScriptFilter.endElement(ScriptFilter.java:131) 在 org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:249) 在 org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:367 ) 在 org.cyberneko 的 org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1015)。html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:888) at org.cyberneko.html.HTMLScanner$SpecialScanner.scan(HTMLScanner.java:2831) at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:809) at org .cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:478) at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:431) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org .apache.xerces.parsers.DOMParser.parse(Unknown Source) at com.meterware.httpunit.parsing.NekoHTMLParser.parse(NekoHTMLParser.java:48) at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:271)在 com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:1301) 在 com.meterware.httpunit.WebResponse.getFrames(WebResponse.java:1285) 在 com.meterware.httpunit.WebResponse。getFrameRequests(WebResponse.java:1024) at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:179) at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:315) at com.meterware.httpunit.WebClient .updateFrameContents(WebClient.java:526) 在 com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:201) 在 com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183) 在 com.meterware.httpunit。 WebWindow.getResponse(WebWindow.java:158) 在 com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:199) 在 com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183) 在 com.meterware.httpunit .WebWindow.getResponse(WebWindow.java:158) 在 com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:199) 在 com.meterware.httpunit.WebWindow。getSubframeResponse(WebWindow.java:183) 在 com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158) 在 com.meterware.httpunit.WebClient.getResponse(WebClient.java:122) 在 Main.main(Main.java :76)
谁能给我一个解决我的问题的解决方案?