IE 9 error getElementbyId: Object required

2020-04-21 07:48发布

for some reason, VBS below works like a charm in IE 8, but in IE9 on both of my Laptops I get Object Required at .getElement.

How can I fix this please.

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

edit

this is what I got so far in JScript

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

1条回答
啃猪蹄的小仙女
2楼-- · 2020-04-21 08:18

You need to use the right names. The names you have given are the Name property, not the ID, so:

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

Should be:

.getElementByID("username").Value = "myuser"
.getElementByID("pass").Value = "mypass"
查看更多
登录 后发表回答