Link to home
Start Free TrialLog in
Avatar of bakerg1
bakerg1Flag for United States of America

asked on

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"  />
Avatar of vb_elmar
vb_elmar
Flag of Germany image

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
Avatar of bakerg1

ASKER

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.
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
Avatar of bakerg1

ASKER

That returned 0 input fields.
...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.
Avatar of bakerg1

ASKER

Yes, that returned [object] in the message box.
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
Avatar of bakerg1

ASKER

I tried this and get the following error:

Line: 3
Char: 8
Error: Expected end of statement
Code: 800A0401
Source: Microsoft VBScript compilation error
Here is a vb6 sample .
4.zip
Avatar of bakerg1

ASKER

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.
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.
Avatar of bakerg1

ASKER

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?
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

Avatar of bakerg1

ASKER

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.
Can you provide the URL?
Avatar of bakerg1

ASKER

I would rather not post it publicly, is there a way I can send it to you privately?
You can send me an email .
ASKER CERTIFIED SOLUTION
Avatar of vb_elmar
vb_elmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bakerg1

ASKER

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!
Avatar of bakerg1

ASKER

vb_elmar went above and beyond to help me resolve this script.  Phenomenal work!!