有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

通过VBA提交jsp站点的Java脚本表单

我需要用VBA代码填写登录表。 我无法对“.Click”方法的任何组合做出任何反应,因此我尝试填写表单,然后调用JS提交函数,但总是出现此错误(作为VBA错误消息框):

Could not complete the operation due to error 80020101

在路上。jsp页面可与以下元素进行交互:

表格本身:

<form id="LoginViewForm" onsubmit="checkOnSubmit(this); return false;"
method="POST" name="LoginViewForm" action="LoginViewController.jsp">
<input type="HIDDEN" name="ControllerAction">
<input type="HIDDEN" name="loginPassword">
<input type="HIDDEN" name="newPassword">

输入框如下所示:

        <td>
            <input name="loginUser" size="20" maxlength="18" type="text"
             tabindex="1" class="inputField" onfocus="this.select();">
        </td>

        <td>
            <input name="dspLoginPassword" size="20" maxlength="18"
            type="password" tabindex="2" class="inputField"
            onfocus="this.select();" autocomplete="off">
        </td>

有一个按钮,点击该按钮可提交表格:

<table id="buttonID1" border="1" cellspacing="0" cellpadding="0"
class="buttonBorderEmphasized">
 <tbody><tr>
  <td id="buttonEmphasized" nowrap="yes"class="buttonTextEmphasized">
   <a href="javascript:submitLogin (document.LoginViewForm);"
   tabindex="3">&nbsp;&nbsp;
   Login&nbsp;&nbsp;</a>
</td></tr></tbody></table>

还有下面的脚本功能,通过上面的按钮启动:

 function submitLogin(form)
 {

  if(validateLogin()) {

    window.document.body.style.cursor = 'progress';
    showStatusMessage();
    form.ControllerAction.value = 'Login';
    form.submit();
    return;

  } else resetSubmitted(); return;

} 

我正在尝试以下代码来处理它(已经尝试了调用java脚本的不同变体,这是最后一个,但仍然不起作用):

 Set objFormMain = IEDoc.Frames("i2ui_shell_content").Document _
 .Frames("results").Document.forms("LoginViewForm")

With objFormMain
    .Elements("LoginUser").Value = 1
    .Elements("dspLoginPassword").Value = 1
    IE.Document.all.Item
    Call IE.Document.parentWindow.execScript("submitLogin(document.LoginViewForm)", "JavaScript")
    .submit
End With

错误本身在“Call IE.Document.parentWindow.execScript”(“submitLogin(Document.LoginViewForm)”,“JavaScript”)行返回

有没有办法修改代码使其正常工作


共 (1) 个答案

  1. # 1 楼答案

    拒绝许可的问题似乎在其他地方得到了很好的记录,例如here。我的建议是,您需要从IE中访问实际的JS错误,以找出问题所在

    当然,还有其他方法来完成这类事情,即使用一个名为Selenium的工具,它有许多语言的绑定,包括VBA。像Selenium这样的工具的优点是:1)它是这类东西的实际选择;2)它适用于所有浏览器,而不仅仅是IE