【发布时间】:2019-08-31 00:13:18
【问题描述】:
我的目标是自动化需要进入某个网站的过程,输入 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
【问题讨论】:
-
我尝试在我这边调试您的代码,我发现您的代码正在单击按钮,但网站上没有任何反应。如果我手动将值粘贴到文本框中并单击按钮,那么网站上也没有发生任何事情。在控制台中,我收到了与 CORS 相关的消息和其他错误。 imgur.com/a/Ka5wSAu 所以请尝试检查您是否能够手动执行此操作以及是否出现任何错误。它可以帮助缩小问题范围。
-
当我手动操作时,它允许我在网页上看到一条错误消息,因为“10101010101”只是一个随机数。当我运行宏时,我什至没有达到这一点。它只是在文本框中引入数字。
-
您能否再次尝试使用正确的输入调试您的代码?请检查您的代码卡在哪一行,当时是否给出任何错误或警告消息?它可以帮助缩小问题范围。
标签: vba internet-explorer svg