的形式.使用VBA时提交不通过

Form.Submit does not go through when using VBA

本文关键字:提交 VBA 使用      更新时间:2023-09-26

我有一个网页,我从中提取数据。我可以做一切与VBA除了点击一个图像元素,然后提交一个表单和一个弹出的数据被创建。

image元素中的一个属性名为"productguid",其字符串值=

" a12 - 545"。

在我用鼠标点击image元素之前,表单的HTML代码如下:

<form id="GetProductQuantitiesForAccessibleBranches" action="GetProductQuantitiesForAccessibleBranches" method="post">
  <input type="hidden" name="ProductGuid" value="">
</form>

这是我用鼠标手动点击后的HTML代码:

<form id="GetProductQuantitiesForAccessibleBranches" action="GetProductQuantitiesForAccessibleBranches" method="post">
  <input type="hidden" name="ProductGuid" value="a12-545">
</form>

基于此,我假设来自image元素的productguid值在提交之前被传递到表单上。这是我的VBA代码看起来像这样:

'Change the input element value
ie.Document.getElementById("GetProductQuantitiesForAccessibleBranches").all.item(0).value = "a12-545"
'Submit the form
ie.Document.getElementyId("GetProductQuantitiesForAccessibleBranches").Submit

根据Locals窗口,所有Javascript事件都是Null。这两行代码运行没有任何错误,但网页不更新。我遗漏了什么吗?

我也试过用.Click方法点击图像元素,但这也不做任何事情。

这个网页有密码保护,所以我不能公开发布URL。

更新:

这是标签中的HTML,通常是手动点击,然后提交表单。也许这里面有什么我能用的?

<img alt="View Quantities At Other Locations" src="/WebOrder/Images/CheckQtys.gif" 
title="View Quantities At Other Locations" class="popup" 
popupdirection="upperleft" popupwidth="380" 
popupcontent="#ProductQuantitiesForAccessibleBranches" 
onbeforepopupcreate="onBeforePopupCreate_GetProductQuantitiesForAccessibleBranches(this)" 
popupajaxformid="GetProductQuantitiesForAccessibleBranches" 
onbeforepopupajaxpost="onBeforePopupAjaxPost_GetProductQuantitiesForAccessibleBranches(this)" 
oncompletepopupajaxpost="onCompletePopupAjaxPost_GetProductQuantitiesForAccessibleBranches(this)" 
productguid="a12-545" 
displayitem="33902" 
brandguid="00000000-0000-0000-0000-000000000000" 
brandname="" brandsku="">

给这个机会,我怀疑这将是一个"完美"的答案,没有实际看到的网站。然而,这应该找到正确的图像标签,假设你没有任何框架/iframe(请检查有没有),和应该点击它。

Public Sub Click_IMG_Tag()
    Dim Elements As Object
    Dim Element  As Object
    'Get a pointer to IE etc first, I'm assuming this is already done
    Set Elements = IE.Document.getElementsByTagName("img")
    For Each Element In Elements
        On Error Resume Next ' used to bypass elements that don't have .Title property
                             ' later, you should error handle this exception
        If Element.Title = "View Quantities At Other Locations" Then
            Element.Focus
            Element.Click
            Element.FireEvent ("OnClick")
            IELoad IE
            Exit For
        End If
    Next
End Sub
Public Sub IELoad(Browser As Object)
    While Browser.busy Or Browser.Readystate <> 4
        Application.Wait (Now() + TimeValue("00:00:01"))
        DoEvents
    Wend
End Sub