使用 VBA 时 Form.Submit 未完成

2023-12-01

我有一个正在从中提取数据的网页。除了单击图像元素然后提交表单并创建包含数据的弹出窗口之外,我可以使用 VBA 完成所有操作。

图像元素中的属性之一称为“productguid”,并且具有字符串值 =

“a12-545”。

在我用鼠标单击图像元素之前,表单的 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>

基于此,我假设图像元素中的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。

UPDATE:

以下是通常手动单击的标记中的 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(请检查是否有),这应该找到正确的图像标签,并且should点击它。

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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 VBA 时 Form.Submit 未完成 的相关文章

随机推荐