如何点击这个按钮?

时间:2013-03-28 10:50:57

标签: vba button click src

大家好我是Visual Basic的初学者。非常感谢您的帮助。

如何在网页中点击此按钮?

<a class="buttonRed" href="what_would_you_do.html" onclick="this.blur();">
  <span>Get Started</span>
</a>

2 个答案:

答案 0 :(得分:2)

对我有用的简短示例,使用简单的html文件进行测试:

<强> ClickA.html:

<!DOCTYPE HTML>
<html lang="en">
<head>
    <title><!-- Insert your title here --></title>
</head>
<body>
    <a class="buttonRed" href="what_would_you_do.html" onclick="this.blur();">
    <span>Get Started</span>
</a>
</body>
</html>

vba标准模块:

' Add References:
' - Microsoft HTML Object Library
' - Microsoft Internet Controls

Sub test()
      Dim Browser As InternetExplorer
      Dim Document As htmlDocument
      Set Browser = New InternetExplorer

      Browser.Visible = True
      Browser.navigate "C:\Temp\VBA\ClickA.html"

      Do While Browser.Busy And Not Browser.readyState = READYSTATE_COMPLETE
          DoEvents
      Loop

      Set Document = Browser.Document
      Dim anchorElement As HTMLAnchorElement
      Set anchorElement = Document.getElementsByClassName("buttonRed").Item(Index:=1)
      anchorElement.Click
      Set Document = Nothing
      Set Browser = Nothing
  End Sub

答案 1 :(得分:0)

实际上这不是一个按钮。它的锚标签。将代码编写为

  <a class="buttonRed" href="what_would_you_do.html">
   <span>Get Started</span>
   </a>

它将重定向到“what_would_you_do.html页面(如果它在root中)