Microsoft VBScript运行时错误';800a01a8&x27;所需对象:';objIE.document.getElementById(..)

Microsoft VBScript运行时错误';800a01a8&x27;所需对象:';objIE.document.getElementById(..),vbscript,Vbscript,我正在尝试自动化一个网页 我可以登录并点击页面。 单击新页面后,我需要在其中输入“Name”,但它不起作用:Microsoft VBScript运行时错误'800a01a8'需要对象:'objIE.document.getElementById(…) 下面是我正在使用的代码 struser = "user" strPass = "pswd" Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = Tru

我正在尝试自动化一个网页

我可以登录并点击页面。 单击新页面后,我需要在其中输入“Name”,但它不起作用:Microsoft VBScript运行时错误'800a01a8'需要对象:'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
struser=“用户”
strPass=“pswd”
Set objIE=CreateObject(“InternetExplorer.Application”)
objIE.Visible=True
objIE.导航“http://myurl"
而objIE.Busy=True
WScript.Sleep 100
温德
而objIE.ReadyState 4
WScript.Sleep 100
温德
objIE.Document.all.User.value=struser
objIE.Document.all.Password.value=strPass
objIE.Document.Forms(0.Submit())
而objIE.Busy=True
WScript.Sleep 100
温德
而objIE.ReadyState 4
WScript.Sleep 100
温德
objIE.Document.all.drop\u主菜单。单击()
objIE.Document.all.BOX.value=“12”
objIE.Document.all.Button.单击()
而objIE.Busy=True
WScript.Sleep 100
温德
而objIE.ReadyState 4
WScript.Sleep 100
温德
“暗淡的srch
'objIE.Document.getElementsByName(“058”).value=“Long”
'srch.value=“Long”
set el=objIE.document.getElementById(“C0_58”)
'如果el.value为空,则
设置el.value=“Long”
"完"
设置WshShell=WScript.CreateObject(“WScript.Shell”)
WshShell.SendKeys“^%L”
下面是该字段的源代码片段。
在这里输入代码
在这里输入代码

令人惊讶的是,我尝试了下面的代码,当从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")
或:


我所能建议的最好办法就是围绕着框架和它们的子元素进行游戏。如果可能的话,你可以发布你的HTML,我们可以看看这是否有效??set el=objIE.document.getElementById(“C0_58”)。。。。。用set el=objIE.document.getElementById(“C0_58”)将ID括在双引号中。如果忘记更新,此字段位于一个iframe内,该iframe内有多个表和跨距。那么objIE对象可能有问题。“objIE.Visible=True”语句是否出现错误。尝试将其置于set el=objIE.document.getElementById(C0_58)之前。。。如果这也引发错误,说明IE对象未正确设置或未正确传递到此对象。你能发布这个对象的来源代码吗?struser=“user”strPass=“pswd”Set objIE=CreateObject(“InternetExplorer.Application”)objIE.Visible=True objIE.Navigate”“While objIE.Busy=True WScript.Sleep 100 Wend While objIE.ReadyState 4 WScript.Sleep 100 WendI厌倦了相同的el.value=“Long”但仍然是同一个问题。这是因为该字段位于一个Iframe中,该Iframe由几个表组成,后跟span和div吗?这些文件在HTML源代码中的位置有什么关系吗?我尝试了以下方法:ObjIE.Document.Frames(“Iframe”).Document.All(“C0_58”).Value=“Long”“这一次我没有收到任何错误,但该字段没有填充值。在谷歌上搜索,我可以看出这一点。你所能做的最好的事情就是,在框架的子元素中循环,看看其中一个名称是否与你的输入框匹配。我正在更新我以前的答案以进行缩进。尝试设置ifr=ObjIE.Document.Frames(“Iframe”).contentwindow.Document.getElementsById(“C0_58”)ifr.value=“Long”,但没有出现错误
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