Microsoft VBScript运行时错误' 800a01a8'需要的对象:' objIE.document.getElementById(..)

时间:2017-06-28 05:06:02

标签: vbscript

我正在尝试自动化网页。

我能够登录并点击页面。 点击新页面后,我需要输入" 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

1 个答案:

答案 0 :(得分:0)

令人惊讶的是,我尝试了以下代码,它在从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( “I帧”)。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,我们可以查看

相关问题