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 a .vbs log in script

Status
Not open for further replies.

novareborn

IS-IT--Management
Oct 11, 2010
10
US
Hi, i really could use some help, i have been working on this script for a few days now. Basically i have been creating a vbs that will log in to multiple tools within tabs if Ie. I have managed to get most of them working. My main problem is that i am trying to set a log in for the log in button does not have a id so i can not use the normal click for a id. also the page for what ever reasons always open in the background so i can not use the send keys to send a enter command once the pass is filled. can i please get some help the simple code is as follows. i stopped it after the pass part because nothing i have tried seem to work. if anyone know how to call the ie to the front then i can use the send keys or if anyone know how to make the code click the button that would be great.

Set objShell = WScript.CreateObject("WScript.Shell")
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = 1
objIE.Navigate "objIE.Visible = True
Wscript.Sleep 2000
objIE.Document.All.Item("username").Value = "username"
objIE.Document.All.Item("password").Value = "pass
 
When you get to the references of various control, you sure need to take in account of what you actually need. For instance, it is sure that you need to enter username and password and/or even to select some option of radio button etc... before submitting.

This is how you make sure to fill up all the boxes before submit.
[tt]
surl= "[ignore][/ignore]"

set oie=createobject("internetexplorer.application")
with oie
.navigate "about:blank"
do while .readystate<>4 : wscript.sleep 50 : loop
.navigate surl
do while .readystate<>4 : wscript.sleep 50 : loop
.visible=true
end with

set cinputs=oie.document.getElementsByTagName("input")
for each obj in cinputs
if strcomp(obj.type,"submit",1)=0 and strcomp(obj.value,"sign in",1)=0 then
'wscript.echo obj.type & vbcrlf & obj.value & vbcrlf & "find it"
'obj.click()
'exit for
[blue]set osubmit=obj[/blue]
end if
if strcomp(obj.type,"text",1)=0 then
obj.value="username"
end if
if strcomp(obj.type,"password",1)=0 then
obj.value="password"
end if
next
[blue]osubmit.click[/blue]
set osubmit=nothing
set cinputs=nothing
set oie=nothing
[/tt]

Furthermore, the textbox and password entry box are retrieved with very rudimentary criteria and are not very robust, even though I have tested the actual page that it can get by no problem. However, I cannot say I am absolutely happy with that as it is not the main point. However to get to the submit button without id or name is the question being asked. On that matter, it can certainly be improved if you look more into how that page is structured. I have not looked into it as thoroughly as I would like.

Also, this kind of manoeuvre is a delicate matter as it involves a couple of technologies. Make sure technically you are ready to do it! But who will admit anything less?
 
tsuji, i like your use of the Set oSubmit = obj, to later use it outside of the For Next, very neat.


I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Hi guys, i am pleased to say that everything works perfect, the key was in that whole cinputs part... I was even able to add that to the bottom of my code that called the ie and it still worked perfect...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top