gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 19:46:26 29 4
gpt4 key购买 nike

我已经搜索了又搜索,但没有找到任何解决方案来解决这个问题,

如何触发 div 内的 onclick 事件?我通过使用标题和 getattribute 测试它,一切都正确,但它就是无法点击。

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 一起使用,是否有其他替代方案?

最佳答案

div.FireEvent "onclick" 应该可以工作(以下示例使用 IE11 进行测试)。也许你的 div 是空的(不包含任何可以点击的内容?)。

用于测试代码的HTML 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事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31221853/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com