1

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); 
Mowgli
  • 3,422
  • 21
  • 64
  • 88
  • Haven't seen VBS in like forever. Why not just re-do it in JavaScript, I'll be for sure more compatible. – elclanrs Jan 09 '13 at 22:14
  • I don't know how to :(. I tried. – Mowgli Jan 09 '13 at 22:17
  • What are you trying to do exactly with this piece of code? – elclanrs Jan 09 '13 at 22:17
  • it will login automatically to the website with my username and password. it works in IE8. – Mowgli Jan 09 '13 at 22:18
  • 1
    I haven't used VBS in years so I might not be the best to answer this question. I would suggest you take a look at the [MDN](https://developer.mozilla.org/en-US/docs/JavaScript) and experiment to do this in JavaScript. It'll be worth the investment. VBS is hardly used in front-end dev anymore, probably only on some intranet stuff and MS applications. – elclanrs Jan 09 '13 at 22:24
  • @elclanrs It looks like he is doing this on his machine, running it in wscript, not using IE to render this as part of some HTML markup. The script is launching IE for him on his local PC, which is where the confusion may be coming from. – John Koerner Jan 09 '13 at 22:31
  • 1
    Oh I see... Well , the actual login part where he grabs the elements and submits the form can be done in JS no problem. I guess to launch the site he could use NodeJS or a simple bash/cmd script. As for the problem, I've read somewhere about IE9 failing to interpret VBS if not in compatibility mode. @Mowgli: Try switching to compatibility mode and see if it works. – elclanrs Jan 09 '13 at 22:38
  • @elclanrs dude you are awesome... how did you know it will work in compatibility mode? – Mowgli Jan 10 '13 at 14:03
  • @Mowgli: I think it might be because IE9 dropped support for deprecated VBS features that are probably still available in old IE. There's a way to always trigger compatibility mode if that's what you want but I would again suggest doing it in JS. – elclanrs Jan 10 '13 at 21:07
  • I still need to learn to write about script in JScript. – Mowgli Jan 10 '13 at 21:47

1 Answers1

1

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"
Fionnuala
  • 90,370
  • 7
  • 114
  • 152
  • No, that is not the problem, I have tried that already, and what I have works already on IE8. – Mowgli Jan 10 '13 at 14:02
  • let me try with compatibility mode and with your code, but looks like problem is with compatibility mode to begin with. – Mowgli Jan 10 '13 at 14:12
  • I just tried both condition and they both work if compatibility mode is on. thanks – Mowgli Jan 10 '13 at 14:16