MSHTML.HTMLElementCollection类型不匹配错误



我正在创建一个将数据复制到Excel的脚本代码。我的代码运行良好,直到找到元素时出现错误type mismatch

Function Login(ID As String, Pass As String) As Boolean
Dim objIE As SHDocVw.InternetExplorer
Dim ieDoc As MSHTML.HTMLDocument

Dim UserID As MSHTML.HTMLInputElement
Dim passwordID As MSHTML.HTMLInputElement
Dim loginb As MSHTML.HTMLInputElement
Dim AllHyperlinks As MSHTML.HTMLElementCollection
Dim hyper_link As MSHTML.HTMLInputElement
Dim link As Object

Set objIE = New SHDocVw.InternetExplorer
objIE.navigate URLstr

Do Until objIE.readyState = READYSTATE_COMPLETE
Loop

Set ieDoc = objIE.document
objIE.Visible = True

Application.Wait Now() + #12:00:02 AM#
Set UserID = ieDoc.all.Item("login/")
UserID.Value = ID
Application.Wait Now() + #12:00:02 AM#
Set passwordID = ieDoc.all.Item("password")
passwordID.Value = Pass
Application.Wait Now() + #12:00:01 AM#
Set loginb = ieDoc.getElementsByClassName("button")(0)
loginb.Click
Do Until objIE.readyState = READYSTATE_COMPLETE
Loop
Application.Wait Now() + #12:00:02 AM#

Set AllHyperlinks = ieDoc.getElementsByTagName("A") 'here i Got Error
For Each hyper_link In AllHyperlinks
If hyper_link.innerText = "search" Then
hyper_link.Click
Exit For
End If
Next

Set objIE = Nothing
End Function

HTML

<a href="javascript:showSearch(true)" title="Search" class="button" id="button_search">
<img src="images/icon_search.gif" alt="">Search

替换代码块:

Set AllHyperlinks = ieDoc.getElementsByTagName("A") 'here i Got Error
For Each hyper_link In AllHyperlinks
If hyper_link.innerText = "search" Then
hyper_link.Click
Exit For
End If
Next

反对:

ieDoc.getElementByID("button_search").Click

最新更新