Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with automating task in broser 1

Status
Not open for further replies.

NEODARK

Technical User
Jul 16, 2007
9
US
Hey guys,

Just found your forum. I'm still a beginner when it comes to .js or .vbs and need some help.

I need to create a scrip which when clicked will help me do the following:

- Upon being clicked from desktop, wait predetermined amount of time (ex, 30 min)
- The script would need to open site - Populate LOGIN + PASSWORD fields, click login button.
- when page loads, find a specific form button, then click update form button.
- send logoff command (logoff link)

This is what I have so far:

Code:
Set objIE=WScript.createobject("internetexplorer.application","objIE")
objIE.visible = True
objIE.TheaterMode = False
objIE.AddressBar = True
objIE.StatusBar = False
objIE.MenuBar = True
objIE.FullScreen = False
objIE.Navigate "about:blank"
Do Until objIE.ReadyState = 4
WScript.Sleep 100
Loop
Set shl = WScript.CreateObject("WScript.Shell")
shl.SendKeys "% X"
URL = "[URL unfurl="true"]www.sitehere.com"[/URL]
objIE.Navigate(URL)

With this I can set the delay, then open the site. But I need help with the sendkeys part to send the login/pass info to populate the fields, I then need to send "enter" after a wait (page load) I need to click a form button & finally click the logoff link.

I need some help b/c this is a bit above what I know. Thank you in advance :D
 
You may want to look and see if the login/pass fields have unique id's and populate them that way.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
They do. I just don't know what the sendkey command is :)

Their form field ID/names are:

ussername
password


respectively, and the login button is submit

:)
 
Sry cant find the edit button on this forum..

I mean I can send the keystrokes with shl.SendKeys "" but since I dont know how to focut the cursor on said field above, it just sends the keys where the default cursor location is (the address bad)

I guess I could send TAB 6 times which places the cursor on the right field, however im not sure how to send the keystroke TAB, not the letters T, A, B.

after that, it could be a few more tabs and one Enter.
 
Thanks, and sorry for all the typos above. I'm used to always going back and editing my posts :p

Anyway, I managed to do what I wanted (sort of) by using this:

Code:
Set objIE=WScript.createobject("internetexplorer.application","objIE")
objIE.visible = True
objIE.TheaterMode = False
objIE.AddressBar = True
objIE.StatusBar = False
objIE.MenuBar = True
objIE.FullScreen = False
objIE.Navigate "[URL unfurl="true"]www.sitehere.com"[/URL]
Do Until objIE.ReadyState = 4
WScript.Sleep 500
Loop
Set shl = WScript.CreateObject("WScript.Shell")
WScript.Sleep 5000
shl.SendKeys "login{TAB}"
WScript.Sleep 1000
shl.SendKeys "password{ENTER}"
WScript.Sleep 5000
shl.SendKeys "{TAB}{TAB}{ENTER}"

which does what I need, however is not fool proof. To make it so, I wish I knew of a way to directly focus on the form fields by NAME/ID. But for now I'll have to rely on TABS :p

unless someone has a suggestions. Thanks for all your help & links ;)
 
Thanks,

I tried as you suggested, which is definitely better, however I keep getting an error on this line:

objIE.Document.All.logonForm.submit

I assume it's because the name of the submit button is also submit, like so:

<INPUT type="submit" name="submit" value="Log On">

This is the code so far:

Code:
Option Explicit

Dim objIE : Set objIE = CreateObject("InternetExplorer.Application")

objIE.Navigate "about:blank"
objIE.Visible = True
objIE.Navigate "[URL unfurl="true"]www.sitehere.com"[/URL]

Do Until objIE.ReadyState = 4
  WScript.Sleep 500
Loop 

objIE.Document.All.logonForm.username.value = "myname"
objIE.Document.All.logonForm.password.value = "123456"
objIE.Document.All.logonForm.submit

As is, the code opens the window, loads the location & enters the values in the correct fields, but fails at the submit part, with "Object doesn't support this property or method: 'Document.All.logonForm.submit"

Thanks again for all your help :)
 
Did you try changing the submit button's name?

Maybe....
objIE.Document.All.logonForm.submit.click()

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I don't have access to actually change the code on the form itself, but "click" worked perfectly :)

Once the form is submitted (I'm logged in) I then need to click another button "ok" on a new page/form. How can I put a pause to wait until the new page is loaded instead of just doing a WScript.Sleep because time always varies (something like what the Do Until objIE.ReadyState = 4) but I can't get it to work right.

There is a note on the code below:

Code:
Option Explicit

Dim objIE : Set objIE = CreateObject("InternetExplorer.Application")

objIE.Navigate "about:blank"
objIE.Visible = True
objIE.Navigate "[URL unfurl="true"]www.sitehere.com"[/URL]

Do Until objIE.ReadyState = 4
  WScript.Sleep 500
Loop

objIE.Document.All.logonForm.username.value = "myname"
objIE.Document.All.logonForm.password.value = "123456"
objIE.Document.All.logonForm.submit.click()
WScript.Sleep 10000
[b]' this is where I need to include code to wait for app ready
' Something like objIE.ReadyState = 4
[/b]
objIE.Document.All.ConfirmForm.ok.click()

Thanks for all your help, this is a great learning experience :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top