【问题标题】:Microsoft VBScript runtime error '800a01a8' Object required: 'objIE.document.getElementById(..)Microsoft VBScript 运行时错误“800a01a8”需要对象:“objIE.document.getElementById(..)
【发布时间】:2020-05-17 21:29:04
【问题描述】:

我正在尝试自动化网页。

我能够登录并点击页面。 单击新页面后,我需要在其中输入“名称”,但它无法正常工作: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

【问题讨论】:

  • 这行得通吗?? set el = objIE.document.getElementById("C0_58")..... 用双引号将 ID 括起来
  • 与 set el = objIE.document.getElementById("C0_58") 相同的错误
  • 忘记更新了,这个字段在一个 iframe 里面,里面有多个表和 span。
  • 那么可能是objIE对象有问题。 'objIE .Visible = True' 语句是否出现错误。尝试将它放在 set el = objIE.document.getElementById(C0_58)...你能把这个objIE的代码贴出来吗?
  • struser = "user" strPass = "pswd" 设置 objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True objIE.Navigate "myurl" 而 objIE.Busy = True WScript。 Sleep 100 Wend While objIE.ReadyState 4 WScript.Sleep 100 Wend

标签: vbscript


【解决方案1】:

令人惊讶的是,我已经尝试了以下代码,当从 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,我们可以看看

【讨论】:

  • 我厌倦了同样的 el.value = "Long" 但仍然是同样的问题。
  • 是不是因为该字段位于一个 Iframe 内,由几张桌子挡住,然后是 span 和 divs ?文件在 HTML 源中的位置是否有任何关系。
  • 我尝试了以下: ObjIE.Document.Frames("Iframe").Document.All("C0_58").Value = "Long" 这次我没有收到任何错误,但是未填充该值。
  • 在谷歌上搜索,我可以找到这个。您可以做的最好的事情是遍历框架的子元素并查看其中一个名称是否与您的输入框匹配我正在更新我以前的答案以用于缩进。
  • 尝试使用 set ifr = ObjIE.Document.Frames("Iframe").contentwindow.document.getElementsById("C0_58") ifr.value = "Long" 但同样,没有弹出错误跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-12
相关资源
最近更新 更多