简体   繁体   English

使用 getElementByID 时出现“需要对象”错误

[英]I Get "object required" error when using getElementByID

I am trying to enter a Username into a text box Using getElementById.我正在尝试使用 getElementById 在文本框中输入用户名。 this generates an "Object required" Error这会生成“需要对象”错误

Dim Myid
Mypsw As String
Dim ie As InternetExplorer
Dim ErrCnt

On Error GoTo ErrorHandler

ChDir "C:\Users\hm_cl\Downloads"
Kill "History.txt"
Myid = "hmclark1959"
Mypsw = "xxxxxxxxx"

Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "https://eteller.dakotalandfcu.com/Centryx/servlet/com.sos.webteller.accountaccess.LoginFrame"
While ie.Busy = True Or ie.readyState < 4: DoEvents: Wend
' ******** The following line generates the error
ie.document.getElementById("LoginID").Value = Myid

ErrorHandler:
MsgBox (Err.Description)

Select Case Err.Number
  Case 53  ' File not found
      Resume Next
  Case 424 ' Object Reuired
      ErrCnt = ErrCnt + 1
      If ErrCnt > 4 Then
        MsgBox (" Unknown Server Side Error")
        ie.Quit
        End
      Else
        Application.Wait (Now + TimeValue("0:00:10"))
        Resume
      End If
  Case Else   'Unknown error
    MsgBox ("There is an unhandled error")
    ie.Quit
    End
End Select

When I click inspect element on the textbox it says the ID="LoginID"当我单击文本框上的检查元素时,它显示 ID="LoginID"

The page still runs in IE.该页面仍在 IE 中运行。 But I give to consider, IE is actively being phased out by MS.但我考虑一下,IE 正在被 MS 积极淘汰。

This is the html part in question这是有问题的 html 部分

 <p id="LoginId"> <label>Login Id</label> <input type="text" name="LoginId" maxlength="32" value="" autocomplete="off" tabindex="0"> <span class="checkdigit"></span> </p>

As you see LoginID is the id of the p tag but you need the input tag to enter your text.如您所见, LoginID是 p 标签的 ID,但您需要输入标签才能输入文本。 The input tag is the first child and than the first sibling in the dom tree from the p tag.输入标签是第一个孩子,而不是 p 标签的 dom 树中的第一个兄弟姐妹。 Try this:尝试这个:

ie.document.getElementById("LoginID").firstChild.nextSibling.Value = Myid

Look here for further information:在这里查看更多信息:
firstChild第一个孩子
nextSibling下一个兄弟姐妹
Something about the Document Object Model (DOM)关于文件 Object Model (DOM)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 getElementById 上的“需要对象”错误 - "Object required" error on getElementById VBA错误:尝试.getElementById时需要“运行时错误&#39;424&#39;对象 - VBA Error: "Run Time Error '424' Object required when attempting to .getElementById 使用IE.Document.getElementById(“info_window”)时所需的错误消息.innerText - Error Message as Object Required while using IE.Document.getElementById(“info_window”).innerText VBA Excel - IE GetElementByID无法正常工作 - 运行时错误424对象必需 - VBA Excel - IE GetElementByID not working - Runtime error 424 Object Required 使用VBA时IF语句中的对象必需错误 - Object required error in IF statement when using VBA 尝试设置范围时,为什么会出现424 Object Required错误? - Why do I get a 424 Object Required error when trying to set the range? 为什么在尝试获取用户输入的工作簿名称时会出现需要对象的错误 - Why am I getting an object required error when trying to get user input for the name of a workbook 如何使用 getElementByID 获取表格? - How do I get a table using getElementByID? 我明显有一个对象时出现对象必需的错误 - Object Required error when I clearly have an object 使用String对象时.Range()。Find()抛出``需要对象&#39;&#39;错误 - .Range().Find() throwing 'Object required' error when using String object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM