VBScript / WshShell - 单击没有名称、ID 或 class 的按钮

VBScript / WshShell - Click Button with no name, id, or class

我想使用 VBScript 在 Internet Explorer 中运行的应用程序的 GUI 中单击一个显示为“添加文档”的按钮。问题是源代码(见下文)中没有“id”、“name”或“class”元素可用作脚本中的参考。

Source Code:

       <TD>
<INPUT type="button" value="Add Document" onclick="addFileUploadBox()">
       </TD>

我的代码在下面,适用于具有源代码 ID 的元素。还包括一些失败的尝试,根据我的谷歌搜索点击有问题的按钮,但我无法开始工作。我是新手,如有任何帮助,我们将不胜感激 - 有任何修复建议吗?

    My Code:

    Dim objIE
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Visible = True

    objIE.Navigate "http://sharemxxxx.xxxxx.com/xxxImport/import.aspx"

    While objIE.Busy
      WScript.Sleep 100
    Wend

    objIE.Document.getElementById("txtReferenceNum").value = "15226002"

    objIE.Document.getElementById("ddlCategory").value = "05"

    objIE.Document.getElementById("btnRetrieve").click

    ' ABOVE CODE WORKS

    ' NOT WORKING #1 - DOES NOTHING - NO ERROR
    '===========================================

    objIE.Document.getElementByType("btn").Value="Add Document"

    For Each btn In objIE.Document.getElementsByTagName("input")
        If btn.Value="Add Document"Then btn.Click()
    Next

    ' NOT WORKING #2 - DOES NOTHING - NO ERROR
    '===========================================
    For Each Button In objIE.Document.getElementsByTagName("input")
     If Button.Value="Add Document"Then Button.Click()
    Next

    ' NOT WORKING #3 - DOES NOTHING - NO ERROR
    '===========================================
Set oInputs = objIE.Document.getElementsByTagName("input")

    For Each elm In oInputs
               If elm.Value = "Add Document" Then
                  elm.Click
                    Exit For
                End If
           Next

    ' NOT WORKING #4 - Show Empty Msg Box
    '===========================================
    set objButtons = objIE.document.getElementsByTagName("input")

    for each objButton in objButtons
            strText = objButton.innerhtml
            msgbox strText
            if (strText = "Add Document") then
                    msgbox "found the button!"
                    objButton.click
                    exit for
            end if
    next 

您可能甚至不需要找到该元素。看起来按钮只是调用了一个 JavaScript 函数。所以你可以使用execScript()函数来运行它。

例如:

objIE.Document.parentWindow.execScript "addFileUploadBox();", "javascript"