英文:
vba Excel getElementsByTagName("a") work but IE.Document.getElementsByClassName("textoblanco") don't work
问题
我使用
Dim IE As InternetExplorerMedium
Set IE = New InternetExplorerMedium
For Each ele In IE.Document.getElementsByTagName("a")
Debug.Print ele.innerhtml
If InStr(ele.innerhtml, "Resolver") > 0 Then Debug.Print "OK": Exit For
next
For Each ele In IE.Document.getElementsByClassName("textoblanco")
Debug.Print ele.innerhtml
If InStr(ele.innerhtml, "Resolver") > 0 Then Debug.Print "OK": Exit For
next
the web page is:
第一个"For Each"有效并执行 Debug.Print "OK",但第二个"For Each"不起作用:运行时错误:438。对象不支持此属性或方法
我尝试从Excel中使用网页
英文:
I use
Dim IE As InternetExplorerMedium
Set IE = New InternetExplorerMedium
For Each ele In IE.Document.getElementsByTagName("a")
Debug.Print ele.innerhtml
If InStr(ele.innerhtml, "Resolver") > 0 Then Debug.Print "OK": Exit For
next
For Each ele In IE.Document.getElementsByClassName("textoblanco")
Debug.Print ele.innerhtml
If InStr(ele.innerhtml, "Resolver") > 0 Then Debug.Print "OK": Exit For
next
the wweb page is:
<a href="javascript:botonDuplicarActividad();" class="textoblanco">Duplicar </a>
<a href="javascript:botonHojaTecnica();" class="textoblanco">Hoja Tec </a>
<a href="javascript:botonResolver();" class="textoblanco">Resolver </a>
The first "For each" work and execute Debug.Print "OK" but the second "For Each" not work: Run time :438. object doesn't support this property or methode
i try use a web page from excel
答案1
得分: 0
以下是您要翻译的代码部分:
Sub Tester()
Dim IE As InternetExplorerMedium, ele As Object
Set IE = New InternetExplorerMedium
IE.Navigate "about:blank"
IE.Document.Body.innerhtml = _
"<a href=""javascript:botonDuplicarActividad();"">Duplicar</a>" & _
"<a href=""javascript:botonHojaTecnica();"">Hoja Tec</a>" & _
"<a href=""javascript:botonResolver();"">Resolver</a>"
Debug.Print "By Tag Name"
For Each ele In IE.Document.getElementsByTagName("a")
Debug.Print , ele.innerhtml
If InStr(ele.innerhtml, "Resolver") > 0 Then Debug.Print , "OK": Exit For
Next
Debug.Print "By Class Name"
For Each ele In IE.Document.getElementsByClassName("textoblanco")
Debug.Print , ele.innerhtml
If InStr(ele.innerhtml, "Resolver") > 0 Then Debug.Print , "OK": Exit For
Next
End Sub
希望这有助于您的需要。
英文:
There's no problem with getElementsByClassName
in IE unless you have a really old version.
This works fine for me:
Sub Tester()
Dim IE As InternetExplorerMedium, ele As Object
Set IE = New InternetExplorerMedium
IE.Navigate "about:blank"
IE.Document.Body.innerhtml = _
"<a href=""javascript:botonDuplicarActividad();"" class=""textoblanco"">Duplicar</a>" & _
"<a href=""javascript:botonHojaTecnica();"" class=""textoblanco"">Hoja Tec</a>" & _
"<a href=""javascript:botonResolver();"" class=""textoblanco"">Resolver</a>"
Debug.Print "By Tag Name"
For Each ele In IE.Document.getElementsByTagName("a")
Debug.Print , ele.innerhtml
If InStr(ele.innerhtml, "Resolver") > 0 Then Debug.Print , "OK": Exit For
Next
Debug.Print "By Class Name"
For Each ele In IE.Document.getElementsByClassName("textoblanco")
Debug.Print , ele.innerhtml
If InStr(ele.innerhtml, "Resolver") > 0 Then Debug.Print , "OK": Exit For
Next
End Sub
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论