Link to home
Start Free TrialLog in
Avatar of qeng
qeng

asked on

need a windows 7 script to load a webpage and automatically enter a username and password

I'm wanting to create a script (some sort of executable file which I can place on my Win 7 desktop and execute by double-clicking it) which will:

open IE
load a pre-defined webpage (e.g. http://somedomain.com)
enter a pre-defined username in the webpage's user login form
enter a pre-defined password in the webpage's user login form
ASKER CERTIFIED SOLUTION
Avatar of Zsolt Pribusz
Zsolt Pribusz

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

ASKER

Zsolt,

Thank you for the reference.  I have started to look into it but since I have little background in scripting, it looks like I will need to spend quite a bit of time familiarizing myself with AutoIt (I downloaded the zip files but couldn't find installation instructions; there are both 32bit and 64bit versions in the zip file and the package includes a number of additional files which I'm not clear how to use/install).

What I've done in the meantime is progressively write my own VBS script which will successfully run from the desktop when double-clicking.

So far my script does the following:

- Defines my desired page URL (say "https://mypage.com)
- Triggers IE and loads my URL
- Defines the Username and Password I will want to pass to the webpage
- Defines the first (static) portion of a secure token (say 'secureToken_firstHalf') i will need to pass to the webpage
- Requests the second (dynamic) portion of the secure token (say 'secureToken_secondHalf') from the User
- Defines the SecureToken I will need to pass to the webpage by concatenating secureToken_firstHalf & secureToken_secondHalf

What I don't know how to do is then, on the secure webpage my script has opened:

- enter (pass) the Username into the Username input box
- enter (pass) the Password into the Password input box
- enter the SecureToken into the Secure Token input box

When I inspect the DOM element on the secure webpage I'm logging into (I have to do this several times a day, hence why I want to automated it) it shows:

for the Username input box:

<input name="username" id="username_5" type="text" size="20">

for the Password input box:

<input id="password_5" type="password" name="password" size="20">

for the SecureToken input box:

<input id="password#2_5" type="password" name="password#2" size="20">


I'm thinking there is something like a getElementbyID function? with a submit? or something but I'm not proficient enough to code this yet.
Avatar of qeng

ASKER

I should have added that the last step I'm trying to accomplish after passing the log-in credentials is to automatically click the 'Log-In' button on the same page.

The Log-In button shows up this way on the webpage:

<input id="btnSubmit_6" type="submit" value="Log In" name="btnSubmit">
SOLUTION
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 qeng

ASKER

Thanks Zsolt but I'm not using AutoIT yet.  I'm simply coding in VBS using Notepad (e.g. creating a script file on my desktop, say mySript.VBS, and executing by double clicking it).

What would the VBS commands be to target the input boxes on the webpage I described above?
Sorry I'm not good with VBS. If you want to do this only in VBS, then someone else need to help you.
But since everything you want, can achieve with AutoIt in seconds (you just need to adapt the script I wrote to your environment), why you not try it out?
Avatar of qeng

ASKER

Zsolt,

Thank you for staying with me on this.  There were a couple of reasons I wanted to do this only in VBS.  The first one is that I don't know how to use AutoIt.  I did download it but I'll need to learn how to use it.  The second and main reason is that I probably won't be able to use AutoIt on my work computer (where I also intend to use the VBS script) since I don't have administrator privileges to install AutoIt.  I suspect that AutoIt probably lets me compile the script into a VBS script but again this is something I don't know how to do.

What I've managed to do so far using VBS alone (using statements like '.getElementByID("username_5").value = "myusername") is to successfully log into the first page of the remote computer.  Which means I was able to pass the Username, Password, Secure Token and to submit the form (equivalent to clicking the LogIn button).

But now I have to make my script target a link on this new page and I don't know how to do that :) ... yet.  The whole log-in process is annoyingly time consuming because it involves several log-in pages; that's why I'm trying to automate it.

Are you able to refer me to one of your colleagues with more VBS experience?
SOLUTION
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 qeng

ASKER

Where I'm at at the moment is my script gets me logged in on the first page, and the second page loads.

On the second page (which I don't know how to target in my script; it becomes the active tab in IE) there is a link which doesn't have an id which I need to 'click' on.

The link is in a table and looks like this:

<table width="100%" id="thetableid" border="0" cellspacing="0" cellpadding="4">
                        <tbody><tr valign="top">
                          <td><img width="18" some code here" border="0"></td>
                          <td width="100%" align="left">
<a href="/somelabel/somelabel2/winlaunchterm.cgi?row=1&amp;index=0&amp;perm=no">sometext</a>                          </td>
                        </tr>
                      </tbody></table>


The link I'm trying to 'click' on from within the script is:
<a href="/somelabel/somelabel2/winlaunchterm.cgi?row=1&amp;index=0&amp;perm=no">sometext</a>

I'm thinking it will look something like:  .getElementByID("thetableid").click() or something like that but I suspect I need some code ahead of that to set the object first and define which of the tabs is the active tab (or define that the current tab is the one I'm needing to target).
Avatar of qeng

ASKER

Zsolt,

Thank you.  I suspected as much but will try to finish my present VBS script before heading into AutoIt.

I'm making progress, albeit slowly, learning as I go.  I'll close out this question and post a new one to continue where I left off.
Avatar of qeng

ASKER

The expert did his best to assist.  The solution required the use of 3rd party software (free) which I'm not familiar with.  I required a solution in VBS script.  I will repost.
One more thing come to my mind. On second page, the link what you need to click is dynamically changing? If not, then just hardcode that link into your script to open it with IE. Since login is done already, it should work.
Avatar of qeng

ASKER

Good call Zsolt.  That idea came to me as well and that's what I had done.

I managed to automate through the two login screens of the Junos Pulse Secure Access Service all the way through startup of the Terminal Session.

The last few pieces I need to add to my script are:

add a delay
send a return keystroke
add a delay
send a return keystroke
send a password
send a return keystroke
I think this will be piece of cake for you now :)
Avatar of qeng

ASKER

Thanks Zsolt,

I got the last pieces working ( used WshShell.SendKeys "{ENTER}" etc. along with delays where I thought I needed them), but ...

The problem I have left is that the correct keystrokes seem to be getting sent but they are not sent into the Terminal Session my script got me logged into, they are sent to the original desktop session where my script started executing (this is likely not the correct IT terminology but you get my drift).

Do you have any idea how I can target the sent keystrokes to be applied to the Terminal Session which Junos Pulse Secure Access Service started after my script logged me in.
I think, you can achieve this, by finding out the title of Junos window, and switch to it with AppActivate.
Check Microsoft article about this: https://technet.microsoft.com/en-us/library/ee156592.aspx