IE VBA如何单击SVG元素

问题描述 投票:0回答:2

我的目标是自动化需要进入某个网站的流程,输入BOL编号,然后单击搜索按钮以查阅文档。

我无法点击搜索按钮。

Dim oBrowser As Object
Dim HTMLdoc As MSHTML.HTMLDocument
Dim htmlInput As MSHTML.HTMLInputElement
Dim htmlColl As MSHTML.IHTMLElementCollection

Set oBrowser = CreateObject("InternetExplorer.Application")

With oBrowser


            'Open Browser
            .navigate "https://www.paquetexpress.com.mx/rastreo-de-envios" 
            .Visible = 1
            Do While .readyState <> 4:
            DoEvents:
            Loop
            Application.Wait (Now + TimeValue("0:00:02"))


            'Enter BOL Number
            Set HTMLdoc = .document
            Set htmlColl = HTMLdoc.getElementsByTagName("INPUT")
            Do While HTMLdoc.readyState <> "complete": DoEvents: Loop
            For Each htmlInput In htmlColl
                If htmlInput.Name = "trackingguides" Then
                     htmlInput.Value = "10101010101"
                     Exit For
                End If
            Next htmlInput


'************* I'm having issues with this section **************

            'Click Search
            Set HTMLdoc = .document
            Set htmlColl = HTMLdoc.getElementsByTagName("svg")
            x = 1
            Do While HTMLdoc.readyState <> "complete": DoEvents: Loop


            For Each htmlInput In htmlColl
                    If InStr(1, htmlInput.outerHTML, "0 0 16 16") > 0 Then
                            If htmlInput.offsetTop > 5 Then
                                htmlInput.Click
                                Exit For
                            End If
                    End If
            Next htmlInput

  '**************************************************************
End With
vba internet-explorer svg
2个回答
0
投票

根据网站和您要做的事情,这应该工作:

HTMLdoc.getElementsByClassName("svg-icon svg-fill")(1).Click


0
投票

这将是一种优化的方法,但页面似乎对我来说很重要

Option Explicit

'VBE > Tools > References:
' Microsoft Internet Controls
Public Sub EnterInfo()
    Dim ie As New InternetExplorer, event_onClick As Object

    With ie
        .Visible = True
        .Navigate2 "https://www.paquetexpress.com.mx/rastreo-de-envios"

        While .Busy Or .readyState < 4: DoEvents: Wend

        With .document
            Set event_onClick = .createEvent("HTMLEvents")
            event_onClick.initEvent "click", True, False
            .querySelector("#tracking__input__container input").Value = "10101010101"
            With .querySelector(".searchicon")
                .FireEvent "onclick"
                .dispatchEvent event_onClick
            End With
        End With
        Stop
        .Quit
    End With
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.