2013-03-28 115 views
2

大家好我是Visual Basic的初学者。非常感谢您的帮助。如何点击此按钮?

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

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

你究竟想要做什么?重定向到页面或在锚点上调用函数单击? – 2013-03-28 11:01:31

+0

我想自动化一些东西。我已经成功地启动了IE。我已成功导航到网址。从网站的第一页我想通过点击这个按钮导航到第二页。我不知道如何自动化(如何点击此按钮) – user2165404 2013-03-28 11:05:55

+0

实际上,这不是一个按钮。它的锚标签。写你的代码为 – 2013-03-28 11:33:14

回答

0

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

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

,它会重定向到“what_would_you_do.html页面(如果它的根)

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