【问题标题】:VBA Automation - Div object is not clickableVBA 自动化 - Div 对象不可点击
【发布时间】:2021-12-05 06:10:34
【问题描述】:

我目前正在 VBA 中创建网络自动化。我在单击“div”组件时遇到困难-> 它没有响应任何单击、onclick、mousedown 等。事件。 我能够将 div 组件作为 VBA 中的对象“捕获”,但是当我尝试这些操作时,它没有响应任何操作。还有它的内部组件。

div 对象:

<div tabindex="0" class="SubForm SubForm-up" role="button" aria-pressed="false" style="width: 140px; height: 26px; float: right;">
<input tabindex="-1" role="presentation" style="width: 1px; height: 1px; overflow: hidden; position: absolute; z-index: -1; opacity: 0;" type="text">
<div class="html-face">הגדרות לחשבון מעבר</div>
</div>

我的代码:

Set frmPane = doc.getElementsByClassName("SubForm SubForm-up")(3)
       frmPane.onclick = frmPane.onmousedown
       frmPane.onclick = frmPane.onmouseup
       
       With frmPane
            .Focus
            '.setAttribute "display", "block"
            '.setAttribute "aria-expanded", "true"
            .Click
            .onclick = frmPane.onmouseup
            .FireEvent "onclick"
            .FireEvent "onmouseover"
            .FireEvent "onmousedown"
            .FireEvent "onmouseup"
            .FireEvent "onkeydown"
            .FireEvent "onkeypress"
            .FireEvent "onkeyup"
           ' .Blur
        End With
        
       
       Set heshbonMaavarObj = frmPane.getElementsByTagName("input")(0)
       With heshbonMaavarObj
            .Focus
            .Click
            .FireEvent "onclick"
            .FireEvent "onmouseover"
            .FireEvent "onmousedown"
            .FireEvent "onmouseup"
            .FireEvent "onkeydown"
            .FireEvent "onkeypress"
            .FireEvent "onkeyup"
            '.Blur
        End With
       
       Set heshbonMaavarObj = frmPane.getElementsByTagName("div")(0)
       With heshbonMaavarObj
            .Focus
            .Click
            .FireEvent "onclick"
            .FireEvent "onmouseover"
            .FireEvent "onmousedown"
            .FireEvent "onmouseup"
            .FireEvent "onkeydown"
            .FireEvent "onkeypress"
            .FireEvent "onkeyup"
            '.Blur
        End With

【问题讨论】:

  • הגדרות לחשבון מעבר
  • 我将 html 代码粘贴在问题和评论中,因为它似乎从问题部分消失了。

标签: html vba internet-explorer automation click


【解决方案1】:

根据您的描述,我创建了一个简单的示例进行测试,我发现内联脚本可以很好地工作。不回复是什么意思?你能提供更多细节吗?

这是我的测试(使用 window.alert() 函数):

Sub TriggerDivClick()
    Dim ie As InternetExplorer
    Dim doc As MSHTML.HTMLDocument
    Dim div As HTMLDivElement
    Dim url As String

    url = "https://localhost:44315/Index.html"
    Set ie = CreateObject("InternetExplorer.Application")

    ie.Visible = True
    ie.navigate url

    While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE
        DoEvents
    Wend

    Set doc = ie.document
    Set div = ie.document.getElementsByClassName("SubForm SubForm-up")(0)
    div.FireEvent "onclick"
    ie.Quit

    Set ie = Nothing
End Sub

<div tabindex="0" class="SubForm SubForm-up" role="button" aria-pressed="false" style="width: 140px; height: 26px; float: right;" onclick="window.alert('Div element clicked...')">
        <input tabindex="-1" role="presentation" style="width: 1px; height: 1px; overflow: hidden; position: absolute; z-index: -1; opacity: 0;" type="text">
        <div class="html-face">הגדרות לחשבון מעבר</div>
    </div>

结果:

【讨论】:

  • 感谢您的回答。问题是这个“div”“位于”一个窗格中,该窗格也是一个 div,位于表格内。当我写没有响应时,我的意思是我将所有这些点击事件都触发到这个 div 并且我没有得到结果,因为我执行了鼠标点击。够清楚吗?
  • 如果是这样的话,我认为问题可能与页面结构有关。您能否提供此页面的链接或完整的页面结构代码,以便我们重现该问题?这将有助于解决问题。
  • 我无法提供此页面的链接。这是一个外部系统,我无法访问其源代码
  • 可能是点击事件后某些页面元素属性发生了变化。在这种情况下,您需要手动更改元素代码。而你提到了internal components,我觉得这应该是使用了一些框架,所以如果没有可以重现这个问题的代码,恐怕我无法确定这个问题的原因并解决它。感谢您的理解。
  • 谢谢。我也认为它使用了一个框架,我可以找到它的来源。我非常感谢您的努力。
猜你喜欢
  • 2014-12-09
  • 1970-01-01
  • 2020-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-02
  • 1970-01-01
  • 2021-12-24
相关资源
最近更新 更多