【问题标题】:Access VBA - Clicking button or invoking javascript on website访问 VBA - 在网站上单击按钮或调用 javascript
【发布时间】:2020-09-11 17:54:36
【问题描述】:

我被难住了。我有填写网站表单字段的 vba 代码,多年来,我已成功单击页面底部的继续按钮。最近,该网站进行的更改使最后一步脱轨 - 点击继续按钮。

按钮的 HTML 代码现在读作:

<input type="submit" name="PaymentProcessor$ButtonContinue" value="Confirm" onclick="javascript:PaymentProcessor_ButtonContinue.disabled=true;__doPostBack(&#39;PaymentProcessor$ButtonContinue&#39;,&#39;&#39;);WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;PaymentProcessor$ButtonContinue&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="PaymentProcessor_ButtonContinue" class="btn btn-default" style="font-weight:normal;font-style:normal;text-decoration:none;" /> 

过去,我将 ieObj 定义为 HTMLInputElement 并单击了这样的按钮:

Set ieObj = iePage.getElementById("PaymentProcessor_ButtonContinue")
ieObj.Click

现在,这不再有效。我没有收到错误,没有任何反应。我可以看到 ieobj 在本地窗口中填充,所以我认为我有正确的句柄,我只是无法操作该对象。

我还尝试了以下方法:

ieObj.FireEvent ("onkeypress")
''no error, no effect
ieObj.FireEvent ("doPostBack")
''error
ieObj.submit
''error- does not support method
ieObj.Value = "continue"
''no error, no effect
ieObj.Value = "confirm"
''no error, no effect

我也尝试直接调用该 html 的 javascript 部分,但我可能做错了:

iePage.parentWindow.execScript "document.getElementById('PaymentProcessor_ButtonContinue').submit();", "javascript"
''gives automation error
iePage.parentWindow.execScript "__doPostBack(&#39;PaymentProcessor$ButtonContinue&#39;,&#39;&#39;);WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;PaymentProcessor$ButtonContinue&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false));", "javascript"
''gives automation error

我尝试使用 queryselector 和 queryselectorall,但是这两种方法都导致 Access 崩溃。

在页面的其他地方,定义了以下 javascript 函数。我不知道是否重要,但它在下面:

<script type="text/javascript">
//<![CDATA[
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>

我应该尝试什么想法?

【问题讨论】:

  • 私人网页/登录后?
  • 是的,支付处理网站的深度约为 5 页。
  • 我认为您应该按如下方式查看回发等:__doPostBack('PaymentProcessor$ButtonContinue','');WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("PaymentProcessor$ButtonContinue", "", true, "", "", false, false)) 以及后半部分的一些背景:docs.microsoft.com/en-us/dotnet/api/…
  • 您是否也尝试过 iePage.parentWindow.execScript "document.getElementById('PaymentProcessor_ButtonContinue').click();", "javascript"
  • 我根据您的建议尝试了 iePage.parentWindow.execScript "document.getElementById('PaymentProcessor_ButtonContinue').click();", "javascript"。没有错误,但没有效果。感谢您的建议。我阅读了您其他评论中的链接,但我不确定如何使用该信息,

标签: javascript vba ms-access


【解决方案1】:

查看输入按钮是否是表单的一部分,并调用表单的“提交”过程。 在不了解更多关于被抓取的 HTML 的情况下,我无法提供进一步的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 2022-08-05
    • 2018-10-27
    • 2022-12-29
    • 1970-01-01
    相关资源
    最近更新 更多