0
在VBA中,如果我使用getElementByID(「id_name」)並且id不存在,則該函數不返回空值。這讓我不知道DOM是否還沒有呈現元素,或者元素是否真的不存在。看起來規範要求返回一個NULL,並且NULL不等於Nothing。所以我的問題是這個DOM函數是否返回NULL,Nothing或者它是否依賴於我失蹤的東西?由於爲什麼getElementByID返回Nothing而不是NULL
snipit
If Not IsNull(p_IE.Document.getElementById(MAIN_SR_CONTAINER)) Then
' If I do not receive NULL I want to assume that I can grab the element.
' Still, I verify that the element is not Nothing
' problem is that NULL <> Nothing so if the element does not exist my code loops for eternity
' I do look at the readystate of the p_IE object and wait till it = 4
' But the elements may be being created by embedded javascript on the fly
Set elMainSRContainer = p_IE.Document.getElementById(MAIN_SR_CONTAINER)
Do While elMainSRContainer Is Nothing
Set elMainSRContainer = p_IE.Document.getElementById(MAIN_SR_CONTAINER)
Loop
:
:
Else
' bail
End If