Can I do this login to a web page better?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
paraic
Newbie
Posts: 4
Joined: Wed Jan 06, 2016 2:42 pm

Can I do this login to a web page better?

Post by paraic » Thu Jan 07, 2016 9:31 am

Hi
Just got MS and I really like its approach.
I have been doing some basic experiments and learning the tool and got it to login to a web app and move around and fill out fields based on a text file with variables. Thanks to user theonex for the basic framework to read a file and feed it into an array.

Given I am just playing with this is there a better way to do what I am doing? it works but feels a little cumbersome.
here is the idea:
- login to a webpage using credentials in a text file
- click on a menu item
- click on a submenu
- scroll down to the end of the page
- enter data into a form, based on variables in the same text file as above
- click OK
- Scroll back up
- Click logout and the click 'return to login page
- repeat for next user in the text file using their unique login and pass and variables

here's the code:

ReadFile>C:\temp\names.txt,allFile
Separate>allFile,CRLF,usernames
If>usernames_count<0
//just exit if the file is empty
Exit>0
Endif
//run>iexplore.exe https://192.168.14.60:9090
//loop through the list of usernames and login for each one
Let>k=0
Repeat>k
Let>k=k+1
Let>This_line=Account_%k%
Let>This_line1=lines_%k%
//Value becomes the "k"th line from file c:\temp\names.txt
Let>Value=usernames_%k%
//Separate the line by ";" giving two items.
//"field_1' is the user name
//"field_2' is the password
//"field_3' is the Group name
//"field_4' is the IP
Separate>Value,;,field
//username field
MouseMove>263,338
LClick

//Set focus on user login field
SetFocus>Login (Stingray Traffic Manager Virtual Appliance: Developer mode :: StingrayTrafficManagerDEV) - Internet Explorer
CapsOff
//send username
Send>%field_1%
Wait>1
Press Tab
Wait>1
Send>%field_2%
Wait>1
//Move to Login button
Press Tab
Wait>0.5
Press Enter
//logs in
Wait>3
//Click on Services
MouseMove>126,126
LClick
Wait>3
//click on Traffic IPs menu item
MouseMove>170,166
LClick
Wait>3
//Scroll down the page
MouseMove>1353,693
LClick
LClick
LClick
Wait>3
SetFocus>Traffic IP Groups - Internet Explorer
CapsOff
//Move to first field in form
MouseMove>263,383
LClick
Send>%field_3%
Wait>1
Press Tab * 5
Wait>1
Send>%field_4%
Wait>0.266

MouseMove>263,654
Wait>2
//Scroll back up
MouseMove>1353,106
LClick
LClick
LClick
Wait>2
//Click on logout
MouseMove>1317,65
LClick
Wait>1
//Click on 'Return to login page'
MouseMove>424,216
LClick
Wait>1

Until>k=usernames_count

Issues:
It basically works except I would like to improve the following:
- launch IE at the start with the login page - just running iexplore didn't do it. Do I need to specify the exact path for IE?
- I get an occasional debug message (see attachment) about not being able to focus the window - this is after adding keyboard automation
- if I compiled an exe (can't until I purchase) can I give it a command line parameter for the file I'm reading?

Thanks all for any feedback.

Paraic

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Can I do this login to a web page better?

Post by Marcus Tettmar » Thu Jan 07, 2016 1:22 pm

Don't automate IE via user simulation. Use the IE functions:

IECreate>ie_ref
IENavigate>ie_ref,www.someurl.com,ieresult
IEWaitDocumentComplete>ie_ref,ieresult
IEFormFill>ie_ref,,,username,Fred,0,r
IEFormFill>ie_ref,,,password,myPassword,submit,r

That will open IE up and go straight to the page, then submit your login details.

** ABOVE IS AN EXAMPLE WITH MADE UP ELEMENT NAMES - DO NOT EXPECT IT TO WORK - YOU WILL NEED TO CHANGE THE ELEMENT NAMES/URL ETC **

Or use WebRecorder to create the code for you.

Or use the IE Find Element Wizard to create the code for you.

See:
http://help.mjtnet.com/article/154-usin ... ent-wizard

http://help.mjtnet.com/article/13-findi ... -web-sites
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts