excel VBA如何点击IE11上的div的onclick事件

我已经search和search,但没有find任何解决scheme来解决这个问题,

我如何触发一个div内的onclick事件? 通过testing它的标题和getattribute,我得到的一切正确,但它只是不会点击。

IE.document.getElementById("btn_header").FireEvent ("onclick") IE.document.getElementById("btn_header").click IE.document.getElementById("btn_header").parentElement.click 

Web代码

 <td> <div id='btn_header' title='BTN' onclick="window.open('http://www.google.com','_blank');"></div> </td> 

我也看到一些网站说,由于某种原因,Fireevent不能使用IE11,还有其他的select吗?

div.FireEvent "onclick"应该工作(下面的例子与IE11testing)。 也许你的div是空的(包含什么地方可以点击?)。

用于testing代码的HTML在这里 。


 ' Add reference to Microsoft Internet Controls (SHDocVw) ' Add reference to Microsoft HTML Object Library Sub TriggerDivClick() Dim ie As SHDocVw.InternetExplorer Dim doc As MSHTML.HTMLDocument Dim div As HTMLDivElement Dim url As String url = "file:///c:/temp/divOnClick.html" Set ie = New SHDocVw.InternetExplorer ie.Visible = True ie.navigate url While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE DoEvents Wend Set doc = ie.document Set div = ie.document.getElementById("btn_header") div.FireEvent "onclick" ie.Quit Set ie = Nothing End Sub