发现错误,找不到getElementById
我从网页中删除了一些数据,并希望切换我的id
,当一个ID没有find。
我试过了:
If IsError(Docx.getElementById("priceblock_ourprice").innerText) Then price = Docx.getElementById("priceblock_saleprice").innerText Else price = Docx.getElementById("priceblock_ourprice").innerText End If
但是,我得到一个错误在IsError(Docx.getElementById("priceblock_ourprice").innerText)
与Object variable or With Block is not set.
任何build议,如何“抓住” Docx.getElementById("priceblock_ourprice").innerText
的错误?
我很感激你的回复!
如果您试图通过ID来定位元素,那么您的非破坏性捕获的select是有限的,但您可以Set
getElementById
的返回并检查任何内容。
dim el as MSHTML.IHTMLElement on error resume next set el = Docx.getElementById("priceblock_ourprice") on error goto 0 If not el is nothing Then price = Docx.getElementById("priceblock_ourprice").innerText Else price = Docx.getElementById("priceblock_saleprice").innerText End If
如果您按集合定位元素,则可以在访问其属性之一(例如.innerText)之前遍历它们以查找第二个唯一标识符。
尝试使用IsObject Funcion
– > IsObject
在你的情况下IF IsObject(Docx.getElementById("priceblock_ourprice")) THEN (...)