excel VBA如何点击IE11上的div的onclick事件 [英] excel VBA how to click on onclick events of a div on IE11
问题描述
我搜索和搜索,但没有找到任何解决方案来解决这个问题,
i have searched and searched but have not find any solution to resolve this,
我如何触发一个div内的onclick事件?我通过测试它的标题和getattribute来获得所有的权利,但它不会点击。
How do i fire an onclick event that is within a div? I am getting everything right by testing it with its title and getattribute but it just wouldn't click.
IE.document.getElementById("btn_header").FireEvent ("onclick")
IE.document.getElementById("btn_header").click
IE.document.getElementById("btn_header").parentElement.click
网页代码
<td>
<div id='btn_header' title='BTN' onclick="window.open('http://www.google.com','_blank');"></div>
</td>
我也看到一些网站说Fireevent不能与IE11一起工作,是否有其他的
I also saw some site saying Fireevent doesn't work with IE11 for some reason, is there any other alternatives to it ?
推荐答案
div.FireEventonclick
应该工作(以下示例用IE11测试)。
也许你的div是空的(什么都不能被点击?)。
div.FireEvent "onclick"
should work (following example tested with IE11).
Maybe your div is empty (contains nothing where could be clicked on?).
用于测试代码的HTML here 。
HTML used to test the code here.
' 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
这篇关于excel VBA如何点击IE11上的div的onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!