直接为 'click' 按钮调用 Javascript

Call Javascript directly for 'click' button

我需要点击 'button' 它没有 id , name 它是 javascipt 的 href ..

尝试使用下面的代码,似乎当我们点击link时,它会触发JavaScript函数:

Sub Main()
    'we define the essential variables

    Dim IE As Object, Data As Object
    Dim ticket As String


    Set IE = CreateObject("InternetExplorer.Application")

    With IE
        .Visible = True
        .navigate ("<the website url>")

        While IE.ReadyState <> 4
            DoEvents
        Wend

        Set Data = IE.Document.getElementsByClassName("appbut")

        Debug.Print Data.Length

        If Len(Data) > 0 Then
            For Each ee In Data

                Set link = ee.getElementsbyTagName("a")(0)
                ' it is better to check whether we could find the a tag.
                'check whether we could get the innertext.
                Debug.Print link.InnerText

                If link.InnerText Like "Cancel" Then

                    'click the link.
                    link.Click

                End If
            Next ee

        End If
    End With
    Set IE = Nothing
End Sub

网页中的代码:

<script>
    function callLookup() {
        alert("Party Search");
    };
    function callCancel() {
        alert("Cancel");
    };
    function callSearch() {
        alert("Search");
    }
</script>
<table  >
    <tr valign="bottom">
        <td colspan="5">
            <table  >
                <tbody>
                    <tr>
                        <td class="butspace"></td>
                        <td class="butspace"></td>
                        <td class="butspace"></td>
                        <td class="butspace"></td>
                        <td class="butspace"></td>
                        <td class="butspace"></td>
                        <td class="butspace"></td>

                        <td class="butspace"></td>
                        <td class="appbut"><a href="javascript:callLookup();">Party Search</a></td>
                    </tr>
                    <tr>
                        <td class="appbut"><a href="javascript:callCancel()">Cancel</a></td>
                        <td class="butspace"></td>
                        <td class="appbut"><a href="javascript:callSearch();">Search</a></td>
                        <td></td>
                        <td></td>
                    </tr>
                </tbody>
            </table>
        </td>
    </tr>

</table>

结果类似于 this。