javascript - IE 9 错误 getElementbyId : Object required

标签 javascript vbscript

出于某种原因,下面的 VBS 在 IE 8 中非常有用,但在我的两台笔记本电脑上的 IE9 中却很有效 我在 .getElement 处得到 Object required。

请问我该如何解决这个问题。

WScript.Quit Main

Function Main
  Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
  IE.Visible = True
  IE.Navigate "http://desistream.tv/en/index.shtml"
  Wait IE
  With IE.Document
    .getElementByID("login_username").value = "myuser"
    .getElementByID("login_password").value = "mypass"
    .getElementByID("frmLogin").submit
  End With
End Function

Sub Wait(IE)
  Do
    WScript.Sleep 500
  Loop While IE.ReadyState < 4 And IE.Busy 
  Do
    WScript.Sleep 500
  Loop While IE.ReadyState < 4 And IE.Busy 
End Sub

Sub IE_OnQuit
  On Error Resume Next
  WScript.StdErr.WriteLine "IE closed before script finished."
  WScript.Quit
End Sub

编辑

这是我到目前为止在 JScript 中得到的

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.Run("Chrome www.desistream.tv", 10, true);
WScript.Sleep(500); 

最佳答案

您需要使用正确的名称。您给出的名称是 Name 属性,而不是 ID,因此:

.getElementByID("login_username").value = "myuser"
.getElementByID("login_password").value = "mypass"

应该是:

.getElementByID("username").Value = "myuser"
.getElementByID("pass").Value = "mypass"

关于javascript - IE 9 错误 getElementbyId : Object required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14247439/

相关文章:

javascript - 将对象添加到服务中的数组

javascript - python : How to count all objects in an array that match a condition?

json - 任何用于在 Classic ASP 中解析 JSON 的好库?

javascript - 在所有浏览器中调用 vbscript 函数以在 body onload 上运行

javascript - 删除 HTML 表格并将其粘贴到网页的另一部分,这可以使用 JQuery 吗?

javascript - nodejs : read from file and store to db, 限制最大并发数据库操作

javascript - 在现有数据上创建 Vue.js 对象

vbscript - 查找事件驱动器的命令

vba - VB6传值和传引用

vbscript - 经典ASP错误处理: Calling a function after an error?