0
votes

I want to use VBScript to click a button that reads “Add Document” in the GUI of an application that runs in Internet Explorer. The problem is there is no “id”, “name” , or “class” element in the source code (see below) to use as a reference in the script.

Source Code:

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

My code is below and works for elements that have source code ids. Also included are some failed attempts to click the button in question based on my googling but I cant get to work. I'm new to this and any help would be appreciated - any suggestions to fix?

    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 
1

1 Answers

0
votes

You probably don't even need to find the element. It looks like the button just calls a JavaScript function. So you can use the execScript() function to run it.

For example:

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