VBScript Automation of IE webpage runtime error

I am currently trying to use the following script to automatically open IE and login to a webpage.  I am getting a runtime error and I cannot figure out what is causing it.  I use a similiar script on another page that works perfectly.  I have tried changing the sleep time from 1000 up to 8000 with no change in the error.  Any help would be appreciated.  The error follows the script.

Set IE = CreateObject("InternetExplorer.Application")
set WshShell = WScript.CreateObject("WScript.Shell")  
IE.Navigate "webpage"
IE.Visible = True

  ' Wait for the page to load.
  Do While IE.Busy Or IE.ReadyState <> 4
   
  Loop

wscript.sleep 4000
IE.Document.All.Item("username").Value = "LoginID"
IE.document.All.Item("password").Value = "PASSWORD"
IE.document.All.Item("submit").Click

The error:
Script: script.vbs
Line 12
Char: 1
Error: Object required: 'IE.Document.All.Item(...)'
Code: 800A01A8
Source: Microsoft VBScript runtime error

The source code:
<h3 class="formField">User Name</h3>
                  <input class="text" name="username" id="username" tabindex="1" type="text"  />
               <h3 class="formField">Password</h3>
                  <input class="text" name="password" id="password" tabindex="2" type="password"  />
bakerg1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vb_elmarCommented:
instead ...
============
IE.Document.All.Item("username").Value = "LoginID"
IE.document.All.Item("password").Value = "PASSWORD"
IE.document.All.Item("submit").Click

try this :
===========
Set ole2 = ie.Document.getElementsByTagName("input")
For Each r In ole2
    If r.Name = "username" Then r.Value = "BillGates"
    If r.Name = "password" Then r.Value = "apollo11"
    If r.Type = "submit" Then
        MsgBox "Do you want to click?"
        r.Click
        Exit For
    End If
Next
0
bakerg1Author Commented:
I did not get a runtime error with that change but it didn't actually fill the fields and select the submit button either.  I also did not get the message.
0
vb_elmarCommented:
This code lists all fields of the type "input". -How many "input" fields do you get as a result ?

Set ole2 = ie.Document.getElementsByTagName("input")
MsgBox "There are " & ole2.length & " input elements in the entire document"
For Each r In ole2
    zz = "r.Name: " & r.Name
    zz = zz & vbCrLf
    zz = zz & "r.Id: " & r.Id
    zz = zz & vbCrLf
    zz = zz & "r.Type: " & r.Type
    zz = zz & vbCrLf
    zz = zz & "r.Value: " & r.Value
    MsgBox zz
Next
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

bakerg1Author Commented:
That returned 0 input fields.
0
vb_elmarCommented:
...and what happens if you make the following query :

Set ole2 = ie.Document
MsgBox ole2

Does the Message Box return

[object]

? -If the Message Box returns [object] it would be very good.
0
bakerg1Author Commented:
Yes, that returned [object] in the message box.
0
vb_elmarCommented:
Try this sample (in this sample the "user input field name" is "user"
and the "password input field name" is  "passwrd") :
=======

Private Sub Command1_Click()

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True

ie.navigate "about:blank"
DoEvents
ie.navigate "http://www.bonusbots.com/support"

    Do While ie.ReadyState <> 4
        DoEvents
    Loop
   
MsgBox "Site loaded. Do you want to log in now ?", vbSystemModal Or vbMsgBoxSetForeground
' -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo- -oo-
Set ole2 = ie.Document.getElementsByTagName("input")
For Each r In ole2
    If r.Name = "user" Then r.Value = "BillGates"
    If r.Name = "passwrd" Then r.Value = "apollo11"
    If r.Type = "submit" Then
        MsgBox "Login button found. -Do you want to click?"
        'r.Click
        Exit For
    End If
Next

End
End Sub
0
bakerg1Author Commented:
I tried this and get the following error:

Line: 3
Char: 8
Error: Expected end of statement
Code: 800A0401
Source: Microsoft VBScript compilation error
0
vb_elmarCommented:
Here is a vb6 sample .
4.zip
0
bakerg1Author Commented:
I looked at the files, as a newbie to this I have no idea what to do with them.  How do I run them?  You have provided phenomenal information, I am beginning to think that this site just will not allow automation, it is a secure site (https) if that makes any difference.  I have tried many options that I have found on the net.  I made some modifications to the previous script you provided and I got it to run without any errors but it still will not fill in the form and submit it.
0
vb_elmarCommented:
The file "4.zip" is written in VB6. Pleas unzip it and run it (it is Visual Basic 6).

>>I tried this and get the following error:
>>Line: 3
>>Char: 8
>>Error: Expected end of statement
>>Code: 800A0401
>>Source: Microsoft VBScript compilation error

It sounds for me your computer isn't ok. -If you have WinXP,
try to install Service Pack 3. Then (I hope) the VBScript will run.
0
bakerg1Author Commented:
I have SP3 already but I work in a very restricted environment.  The few VBscripts I run are created with a text editor and saved as .vbs and then I simple dbl-click the file to run the script.  That is why I was lost with the three files you uploaded, how do I execute them as a script from this restricted environment?
0
vb_elmarCommented:
If you want to run the script using a .VBS file then put the
following code on temp.vbs and run it.

Set ie = CreateObject( "InternetExplorer.Application" )
ie.Visible = True
ie.Navigate2 "http://www.bonusbots.com/support"
 
Do While ie.Busy
    WScript.Sleep 100
Loop

MsgBox "Site loaded. Do you want to log in now ?", vbSystemModal Or vbMsgBoxSetForeground

Set ole2 = ie.Document.getElementsByTagName("input")
For Each r In ole2
    If r.Name = "user" Then r.Value = "BillGates"
    If r.Name = "passwrd" Then r.Value = "apollo11"
    If r.Type = "submit" Then
        MsgBox "Login button found. -Do you want to click?"
        'r.Click
        Exit For
    End If
Next

Open in new window

0
bakerg1Author Commented:
I tried that code with the following modification: changed user to username and passwrd to password.  It loads the website and then I get the message box that the site loaded and I select "OK" and then it just sits there, nothing is populated into the username and password fields.  No errors either.
0
vb_elmarCommented:
Can you provide the URL?
0
bakerg1Author Commented:
I would rather not post it publicly, is there a way I can send it to you privately?
0
vb_elmarCommented:
You can send me an email .
0
vb_elmarCommented:
Instead ...
 /wtk/html/ess/logon.jsp"
you have to navigate to ...
 /wpk/html/kronos-logonbody.jsp?ESS=true"

If you have modified the URL put the following code on temp.vbs and run it.
Set ie = CreateObject( "InternetExplorer.Application" )
ie.Visible = True
ie.Navigate2 "https:// [enter your URL here.]"

Do While ie.Busy
    WScript.Sleep 100
Loop

WScript.Sleep 2000
'#####################
    Dim ole2
    Set ole2 = ie.Document.getElementsByTagName("input")

For Each r In ole2
    If r.Name = "username" Then r.Value = "BillGates"
    If r.Name = "password" Then r.Value = "apollo11"
    
    If r.Type = "image" And r.classname = "btnLogin" Then
        i = MsgBox("Login button found. -Do you want to click?", vbSystemModal Or vbYesNo)
           If i = vbYes Then r.Click
        Exit For
    End If
Next

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bakerg1Author Commented:
That did the trick.  Awesome work finding the alternate url.  I would award you more points if I could, you deserve everyone of them!!  Thanks again!
0
bakerg1Author Commented:
vb_elmar went above and beyond to help me resolve this script.  Phenomenal work!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.