在Excel VBA中使用getElementsByClassName [英] Using getElementsByClassName in Excel VBA
本文介绍了在Excel VBA中使用getElementsByClassName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我正在使用的代码,但是出现以下错误:
Below is the code which I'm using but I'm getting this error that:
对象不支持此属性或方法
object doesn't support this property or method
,同时使用getElementsByClassName
.
我正在使用的新2变量没有填充,请帮助我,如果我做错了方法,请告诉我.
while using getElementsByClassName
.
The new 2 variable I'm using is not getting filled please help me out, do let me know if I'm doing it the wrong way.
Sub PopulateTasks()
'Variable Declaration
Dim ie As Object
Dim noTaskText As String
Set ie = CreateObject("InternetExplorer.Application")
url = "http://example/do/"
.Visible = True
.Navigate url
.Top = 50
.Left = 430
.Height = 400
.Width = 400
Do Until Not ie.Busy And ie.readystate = 4
DoEvents
Loop
End With
Set link = ie.Document.getElementsByTagName("a")
For i = 1 To 200
For Each l In link
If l.innertext = storyIds(i) Then
l.Click
Do Until Not ie.Busy And ie.readystate = 4
DoEvents
Loop
If InStr("No tasks have been defined.", ie.Document.Body.outerText) <> 0 Then
noTaskFound = True
End If
noTaskText = ie.Document.getElementsByClassName("highlighted_message")(0).innerText
If noTaskFound = True Then
End If
Next
ie.Document.getElementbyId ("")
Do Until Not ie.Busy And ie.readystate = 4
DoEvents
Loop
Next i
End Sub
推荐答案
要获取具有类名的元素,我将使用querySelector:
To get an element with the class name, I would use querySelector:
Set element = ie.Document.querySelector(".classname")
Debug.Print element.innerHTML
以您的示例为例:
txt = ie.Document.querySelector(".highlighted_message").innerText
If txt = "No tasks have been defined." Then
noTaskFound = True
Exit For
End If
这篇关于在Excel VBA中使用getElementsByClassName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文