我的目标是使需要进入某个网站的过程自动化,输入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
答案 0 :(得分:0)
根据网站和您要执行的操作,这应该可以:
HTMLdoc.getElementsByClassName("svg-icon svg-fill")(1).Click
答案 1 :(得分: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