【问题标题】:How is it possible to click on a button on website using VBA?如何使用 VBA 单击网站上的按钮?
【发布时间】:2019-06-13 14:46:42
【问题描述】:

我想使用 VBA 代码单击网站上的一个按钮。 。这就是按钮的 HTML 代码的样子。

我写了这段代码来点击按钮

Set the_input_elements = objIE.document.getElementsByTagName("a")

For Each input_element In the_input_elements

  If input_element.className = "big_button" _
      And input_element.href = "javascript:changePageToFrontdoor(false);" Then

    input_element.Click
    Exit For

  End If

Next

但是,这不是单击按钮。没有错误信息。页面没有发生任何事情。

谁能告诉我我的错误在哪里?

谢谢你:)

【问题讨论】:

  • 您的代码运行时页面可能未完全加载。尝试添加等待。

标签: html vba button


【解决方案1】:

类似这样的东西

Sub Login()
    Dim IeApp As InternetExplorer
    Dim IeDoc As Object
    Dim ieTable As Object
    Set IeApp = New InternetExplorer
        IeApp.Visible = True
            IeApp.Navigate "http://yourlink.com"
            Do While IeApp.Busy: DoEvents: Loop
            Do Until IeApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
            Set IeDoc = IeApp.document
            Set the_input_elements = IeDoc.getElementsByClassName("big_button")
            For Each input_element In the_input_elements
                If input_element.href = "javascript:changePageToFrontdoor(false);" Then
                    input_element.Click
                    Exit For
                End If
            Next input_element
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-05
    • 2021-12-16
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 2016-09-20
    相关资源
    最近更新 更多