javascript - 使用 VBA 时 Form.Submit 不通过

标签 javascript html vba dom browser-automation

我有一个要从中提取数据的网页。除了单击图像元素然后提交表单并创建包含数据的弹出窗口之外,我可以使用 VBA 做任何事情。

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

“a1​​2-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。

更新:

这是标签中的 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

关于javascript - 使用 VBA 时 Form.Submit 不通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39111278/

相关文章:

css - 如何避免CSS类名的名称冲突

html - 在不使用 HTML 5 标签的情况下使用 HTML 5 Doctype `&lt;!DOCTYPE html>` 是否有任何优点?

html - 将 RMarkdown 编织成 HTML 时如何设置主题?

sql - 为 MS Access 编写 SQL 查询

excel - Powershell等待Excel中执行宏

javascript - 在网页上添加大量声音的最佳方式?

javascript - 单击单选按钮应自动定位到页面顶部

javascript - 绘制始终指向远离对象的箭头

excel - Erl() 函数在 64 位 O365 Excel VBA 中不起作用

javascript - 使用 Ramda 镜头更改多个对象