IE 9错误getElementbyId:需要对象

时间:2013-01-09 22:11:49

标签: javascript vbscript

出于某种原因,下面的VBS就像IE 8中的魅力一样,但在我的两款笔记本电脑上都是IE9 我在.getElement获得了对象。

我该如何解决这个问题。

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); 

1 个答案:

答案 0 :(得分:1)

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

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

应该是:

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