repeat with multiple usernames

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

repeat with multiple usernames

Post by theonex » Wed Feb 12, 2014 10:52 pm

hello guys

i have been searching for a way to do this but i am not so good with this so am gonna see if i can get a solution here. what i am trying to do is navigate to a web site login do some stuff logout close the window repeat the whole process again using a different username i would prefer if the usernames and passowords could be stored in a txt file or excel sheet. here is an example of the code.



//Move the mouse cursor out of harm's way to avoid causing mouseover events to interrupt
MouseMove>0,0
Let>delay=1
IE_Create>0,IE[0]

IE_Navigate>%IE[0]%,(URL),r
IE_Wait>%IE[0]%,r
Wait>delay

Let>FrameName={""}
Let>FormName={""}
Let>FieldName={"ctl00$bodyContent$UserName"}
Let>FieldValue={"email address"}
IE_FormFill>%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0,r

Let>FrameName={""}
Let>FormName={""}
Let>FieldName={"ctl00$bodyContent$Password"}
Let>FieldValue={"Password"}
IE_FormFill>%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0,r

Let>FrameName={""}
Let>FormName={""}
Let>TagValue={"Sign In"}
IE_ClickTag>%IE[0]%,str:FrameName,str:FormName,A,TEXT,str:TagValue,r



//do something

//Recorded Events
Let>WW_TIMEOUT=5
CapsOff
MouseMove>1220,170
Wait>2.3
LClick
Wait>3.71
WaitWindowOpen>Home Page - Windows Internet Explorer
WaitReady>Home Page - Windows Internet Explorer
CloseWindow>Home Page - Windows Internet Explorer


i appreciate any help with this

and many thanks in advance :)

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

Post by Marcus Tettmar » Thu Feb 13, 2014 9:08 am

Create a text file (e.g. using Notepad) that looks like this:

Code: Select all

username1
username2
username3
etc
Let's imagine you've saved this file as C:\usernames.txt

Now *after* your IECreate line add this code:

Code: Select all

ReadFile>c:\usernames.txt,allFile
Separate>allFile,CRLF,usernames
If>usernames_count=0
  Exit>0
Endif
Let>k=0
Repeat>k
  Let>k=k+1
  Let>this_username=usernames_%k%
Then change this line:

Let>FieldValue={"email address"}

To:

Let>FieldValue=this_username

Then after you've done what you need to do and BEFORE closing IE, add this line:

Until>k=usernames_count

Now, what will happen is it will loop through the lines in the file, perform the navigate and log in and whatever happens after that and then when that is done it will loop back to the top and navigate back and log in for the next username, etc.

So your code becomes something like:

Code: Select all

//read the file of usernames
ReadFile>c:\usernames.txt,allFile
Separate>allFile,CRLF,usernames
If>usernames_count=0
  //just exit if the file is empty
  Exit>0
Endif

//create IE instance
IE_Create>0,IE[0]

//loop through the list of usernames and login for each one
Let>k=0
Repeat>k
  Let>k=k+1
  Let>this_username=usernames_%k%

  IE_Navigate>%IE[0]%,(URL),r
  IE_Wait>%IE[0]%,r
  Wait>delay
  Let>FrameName={""}
  Let>FormName={""}
  Let>FieldName={"ctl00$bodyContent$UserName"}
  Let>FieldValue={"email address"}
  IE_FormFill>%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0,r
  Let>FrameName={""}
  Let>FormName={""}
  Let>FieldName={"ctl00$bodyContent$Password"}
  Let>FieldValue={"Password"}
  IE_FormFill>%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0,r
  Let>FrameName={""}
  Let>FormName={""}
  Let>TagValue={"Sign In"}
  IE_ClickTag>%IE[0]%,str:FrameName,str:FormName,A,TEXT,str:TagValue,r

  //do something
  
  //log out
  
  //DO NOT CLOSE IE just yet - we want it open so we can loop back to the navigate
  //there's no point closing and reopening it ... 
Until>k=usernames_count
Note you will need to add code to log out. And I would NOT close IE until AFTER the loop. Leave it open so it's quicker and will zoom back to the navigate back to the login page.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

Post by theonex » Sat Feb 15, 2014 4:42 pm

thanks marcus for the reply and solution

one last question if i also wanted a text file containing the passwords how do i get the macro to read of that to on the same script.

many thanks

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

Post by Marcus Tettmar » Sun Feb 16, 2014 5:26 pm

Same way. But if I were you I'd put both in the same file:

username1;password1
username2;password2

Read exactly the same as before but SPLIT each entry:

Separate>this_line,;,parts

Username is in parts_1
password is now in parts_2
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

Post by theonex » Sun Feb 16, 2014 9:06 pm

thank you marcus for taking the time to help me out here
i am a nop. i cant get the password to be red this is what i got so fare if you could just fix this for me.

//read the file of usernames
ReadFile>C:\Users\Public\usernames.txt,allFile
Separate>this_line,;,parts
If>usernames_count=0
//just exit if the file is empty
Exit>0
Endif


//loop through the list of usernames and login for each one
Let>k=0
Repeat>k
Let>k=k+1
Let>this_username=usernames_%k%


Let>MSG_STAYONTOP=1
Let>MSG_XPOS=0
Let>MSG_YPOS=0
Message>this_username
wait>3


Let>MSG_STAYONTOP=1
Message>?
wait>3

Until>k=usernames_count

thanks in advance

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