【问题标题】:How to click on Submit button using VBA如何使用 VBA 单击提交按钮
【发布时间】:2017-12-01 18:31:32
【问题描述】:

我有一个网页,我想自动登录并使用 vba 点击提交按钮,代码如下

'start a new subroutine called SearchBot
Sub SearchBot()

    'dimension (declare or set aside memory for) our variables
    Dim objIE As InternetExplorer 'special object variable representing the IE browser
    Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
    Dim y As Integer 'integer variable we'll use as a counter
    Dim result As String 'string variable that will hold our result link

    'initiating a new instance of Internet Explorer and asigning it to objIE
    Set objIE = New InternetExplorer

    'make IE browser visible (False would allow IE to run in the background)
    objIE.Visible = True

    'navigate IE to this web page (a pretty neat search engine really)
    objIE.navigate "mywebpage"

    'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

    'in the search box put cell "A2" value, the word "in" and cell "C1" value
    objIE.document.getElementById("loginID").Value = ("userid")
    objIE.document.getElementById("password").Value = ("password")

在这段代码之后,我想使用 vba 点击提交按钮

HTML 检查元素代码如下

<INPUT class=btn2 type=submit value=Submit name=submit1>

【问题讨论】:

标签: excel vba


【解决方案1】:

尝试按名称查找元素并单击它。

objIE.document.getElementsByName("submit1")(0).click

【讨论】:

猜你喜欢
  • 2016-03-13
  • 1970-01-01
  • 1970-01-01
  • 2022-10-22
  • 2020-08-15
  • 2011-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多