2016-10-19 61 views
0

我是比较新的VBA,我想实现这个弹出内部的标签,如何单击使用VBA在Internet Explorer

  1. 浏览URL,
  2. 点击打开一个一个按钮弹出一个有3个标签
  3. 单击第三个标签
  4. 废料一些信息

我已经成功与1和2对,但我无法点击任何使用VBA弹出内的选项卡。

这是弹出的Html代码片段。

'<ul class="clearfix" id="historyTabs"> 
      <li class="ajaxCall jsonpCall selected" id="Tab1"><a href="javascript:;">Some Details</a></li> 

      <li class="ajaxCall" id="Tab2"><a class="Class1" href="javascript:;">More Details</a></li> 

      <li id="Tab3"><a href="javascript:;">Even more Details</a><span id="Tab31" style="display: none;"></span></li> 
     </ul> 

我试图

y = 1 
Set ec = HTML.getElementsByTagName("li") 
For Each e In ec 
    idvalue = e.getAttribute("id") 
    If idvalue = "Tab3" Then 
     idinnertext = e.innerText 
     Sheets("Sheet2").Cells(y, 1).Value = idinnertext 
     e.click 
    Else 
     Sheets("Sheet2").Cells(y, 2).Value = "Not Tab3" 
     y = y + 1 
    End if 
Next e 

代码写出“更详细信息,”在我的Excel工作表,但不单击该选项卡。

请求帮助。

感谢, Akilesh

+0

你试过.FireEvent( “点击”)也,何不的getElementById( “TAB3”)? –

+0

@Nathan_Sav:尝试了两种方法弥敦道。 FireEvent(“Click”)我得到一个'无效参数'的错误,GetElemenetByID不做任何事情。 –

+0

弹出窗口将会出现另一个浏览器实例,因此您需要先搜索标题然后在该浏览器实例中搜索“Tab3”来查找该新窗口。看来您的当前代码正在浏览器的父级实例中搜索Tab3。 –

回答

0

不张贴的每本身的答案,这里只是更好的格式。像这样的东西,你需要建立。它使用Microsoft Internet控件和HTML对象库。

希望它可以帮助

Sub n() 

Dim arrExplorerWindows As SHDocVw.ShellWindows 
Dim objIE As InternetExplorer 
Dim intExplorerWindowLoop As Integer 
Dim doc As MSHTML.HTMLDocument 
Dim eleTab As MSHTML.IHTMLElement 

Set arrExplorerWindows = New SHDocVw.ShellWindows 

For intExplorerWindowLoop = 0 To arrExplorerWindows.Count - 1 

    If arrExplorerWindows(intExplorerWindowLoop).Name = "Internet Explorer" Then 
     If arrExplorerWindows(intExplorerWindowLoop).LocationURL = _ 
      "http://www.investinganswers.com/" Then 
      Set objIE = arrExplorerWindows(intExplorerWindowLoop) 
      Set doc = objIE.Document 
      Set eleTab = doc.getElementById("Tab3") 
      eleTab.Click 
     End If 
    End If 

Next intExplorerWindowLoop 

End Sub 
相关问题