我正在通過Powershell訪問InternetExplorer.Application
COM。我試圖使用document
的querySelector
,但它不返回任何結果。我目前正在使用IE8。querySelector所有的IE COM在IE 8中都不起作用
$ie = New-Object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.Navigate("www.google.com")
if ($ie.Busy) { Start-Sleep 1 }
# This statement works
@($ie.Document.getElementsByTagName("a"))[0]
# This statement doesn't work, though querySelectorAll
# exist in the document object
@($ie.Document.querySelectorAll("a"))[0]
# I tried this
$ie.Document.querySelectorAll("a") -eq $null # evaluates to True
你會得到什麼錯誤信息?它返回什麼? – ManseUK
'querySelectorAll'不返回任何東西。它返回null。 – OnesimusUnbound
在我的機器上嘗試了您的代碼,並得到:「方法調用失敗,因爲[mshtml.HTMLDocumentClass]不包含名爲'querySelectorAll'的方法。」 –