簡體   English   中英

Microsoft VBScript 運行時錯誤“800a01a8”需要對象:“objIE.document.getElementById(..)

[英]Microsoft VBScript runtime error '800a01a8' Object required: 'objIE.document.getElementById(..)

我正在嘗試自動化網頁。

我能夠登錄並單擊頁面。 單擊新頁面后,我需要在其中輸入“名稱”,但無法正常工作:Microsoft VBScript 運行時錯誤 '800a01a8' Object required: 'objIE.document.getElementById(..)

下面是我正在使用的代碼

struser = "user"
strPass = "pswd"
 Set objIE = CreateObject("InternetExplorer.Application")
 objIE.Visible = True
objIE.Navigate "http://myurl"
While objIE.Busy = True
WScript.Sleep 100
Wend
While objIE.ReadyState <> 4
WScript.Sleep 100
Wend
objIE.Document.all.User.value = struser
objIE.Document.all.Password.value = strPass
objIE.Document.Forms(0).Submit()
While objIE.Busy = True
WScript.Sleep 100
Wend
While objIE.ReadyState <> 4
WScript.Sleep 100
Wend
objIE.Document.all.drop_mainmenu.click()
objIE.Document.all.BOX.value = "12"
objIE.Document.all.Button.Click()
While objIE.Busy = True
WScript.Sleep 100
Wend
While objIE.ReadyState <> 4
WScript.Sleep 100
Wend
'dim srch
'objIE.Document.getElementsByName("0_58").value = "Long"
'srch.value = "Long"
 set el = objIE.document.getElementById("C0_58") 
'If el.value is nothing Then
 set el.value = "Long"
'End If
 Set WshShell = WScript.CreateObject("WScript.Shell")
 WshShell.SendKeys "^%L"

below is the snippet of source code for that field.

enter code here<input name="0_58" tabindex="6" title="Alpha Name" class="textfield" id="C0_58" style="width: 218px; 
vertical-align: top; cursor: auto;" onmouseover="updateHelpCursor('',this)" onhelp="hp('0_58')" 
onfocus="FCHandler.onFocus(this,'',false)" onblur="FCHandler.onExit(this,false,'',false)" 
type="text" maxlength="40" value=" " htmlpostflag="false">

enter code here

令人驚訝的是,我嘗試了下面的代碼,當從 vbs 文件保存和執行時,它工作得很好。

 Set objIE = CreateObject("InternetExplorer.Application")
 objIE.Visible = True
 objIE.Navigate "https://www.google.co.in/"
 Wscript.Sleep(5000)

 Set objEL = objIE.Document.GetElementById("lst-ib")
 objEL.Value = "Mithilesh"
 MsgBox objEL.Value 'Displays Mithilesh

此外,以下內容可能無法解決您遇到的錯誤,但請查看我在字段中設置值的方式。 你不應該使用

set el.value = "Long"

而是使用

el.value = "Long"

試試這個

ObjIE.Document.Frames("Iframe").contentwindow.document.getElementsById("C0_58")

或者:

For Each frame In iframes
    Set inputs = frame.contentwindow.document.getElementsByTagName("input")
    For Each obj In inputs
        If obj.className = "C0_58" Then
            'MsgBox "found "C0_58" in frame:" & i
        End If
    Next
i = i + 1
Next

我能建議的最好方法是圍繞框架及其子元素進行游戲。 如果可能,你可以發布你的 HTML,我們可以看看

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM