Solved

VBScript Automation of IE webpage runtime error

Posted on 2012-04-04
20
1,758 Views
Last Modified: 2012-04-10
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"  />
0
Comment
Question by:bakerg1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 10
20 Comments
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37807270
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
 

Author Comment

by:bakerg1
ID: 37807978
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
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37808081
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bakerg1
ID: 37808251
That returned 0 input fields.
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37808298
...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
 

Author Comment

by:bakerg1
ID: 37808328
Yes, that returned [object] in the message box.
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37809506
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
 

Author Comment

by:bakerg1
ID: 37811717
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
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37812649
Here is a vb6 sample .
4.zip
0
 

Author Comment

by:bakerg1
ID: 37812751
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
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37813194
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
 

Author Comment

by:bakerg1
ID: 37816259
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
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37816862
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
 

Author Comment

by:bakerg1
ID: 37816963
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
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37817308
Can you provide the URL?
0
 

Author Comment

by:bakerg1
ID: 37823297
I would rather not post it publicly, is there a way I can send it to you privately?
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37824753
You can send me an email .
0
 
LVL 17

Accepted Solution

by:
vb_elmar earned 500 total points
ID: 37828442
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
 

Author Comment

by:bakerg1
ID: 37829803
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
 

Author Closing Comment

by:bakerg1
ID: 37829813
vb_elmar went above and beyond to help me resolve this script.  Phenomenal work!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question