0

I'm sure that this is a repeat post, but I've been unable to find exactly what I need. I currently live on a college campus where I need to enter a username and password to use the internet. I'm trying to automate the process (using .bat files) so I can run a server application on startup without ever pressing a key. Unfortunately, I keep getting an error at line 9 char 9: "Object does not support this property or method: 'getElementByID'" I tried replacing .getElementByID with .getElementByName, but it didn't make a difference.

Call Main

Function Main
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate "https://caserver.jbu.edu/auth/perfigo_weblogin.jsp"
Wait IE
With IE.Document
    .getElementByID("username").value = "name"
    .getElementByID("password").value = "password"
    .getElementByID("tx_voputilities_pi1[sign_in]")(0).Submit
End With
End Function

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

I think that the problem has to do with the webpage. The "username" and "password" fields are elements inside a table. I couldn't find an example webpage with similar properties, so I'm at a loss. I'm not sure if the authentication page can be viewed from off-campus, so I attached a picture with some of the HTML (or at least the elements list)

Html info

My research so far:

VBScript to Launch a website login

IE 9 error getElementbyId: Object required

VBScript get contents of html table text input field

VBS website login script - "Object required" error

Like I said, I'm using batch files to start a computer. I wanted this to be a quick (and, yes, crude) solution, but there may be a better way to automate webpage logon. If there is a [quick] better way, feel free to point me in the correct direction.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MPStoering
  • 184
  • 2
  • 12

1 Answers1

0

Your problem may be that they don't use id, but name instead.

There is no function getElementByName, but there is getElementsByname

You could try

.getElementsByName("username")[0].value = "name"
.getElementsByName("password")[0].value = "password"

(I should probably note that this assumes the first element with these names is the one you are looking for - names do not have to be unique hence the array returned and the lack of a getElementByName function, whereas id is unique)

As a further note, your problem is not that the fields are in a table - getting an element from the DOM with either getElementById or getElementsByName do not take positioning into account, only that the element exists somewhere within the parent you are running the function on.

Tim
  • 491
  • 3
  • 6