reading username and password from text file

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

reading username and password from text file

Post by theonex » Fri Aug 15, 2014 5:24 pm

i need help to add the password to this script any help would be appreciated.
i been pulling hairs over this and i am still clueless.


//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=this_username
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=this_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

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: reading username and password from text file

Post by JRL » Fri Aug 15, 2014 6:19 pm

Where will the passwords be coming from? Are they in the same file as the usernames?

I would change the line:
If>usernames_count=0
to
If>usernames_count<2
Which will also account for file does not exist.

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

Re: reading username and password from text file

Post by theonex » Sun Aug 17, 2014 6:35 pm

both the user name and password would be in the same txt file separated by ; e.g
username1;password1
username2;password2
username3;password3

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: reading username and password from text file

Post by JRL » Mon Aug 18, 2014 3:23 pm

This should be close:

Code: Select all

//read the file of usernames
ReadFile>c:\usernames.txt,allFile
Separate>allFile,CRLF,usernames
If>usernames_count<2
//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
  //Value becomes the "k"th line from file c:\usernames.txt
  Let>Value=usernames_%k%

  //Separate the line by ";" giving two items.
  //"This_User_1'  is the user name
  //"This_User_2'  is the password
  Separate>Value,;,This_User

  IE_Navigate>%IE[0]%,(URL),r
  IE_Wait>%IE[0]%,r
  Wait>delay
  Let>FrameName={""}
  Let>FormName={""}
  Let>FieldName={"ctl00$bodyContent$UserName"}

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

  //Enter the password "This_User_2"
  Let>FieldValue=This_User_2
  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

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

Re: reading username and password from text file

Post by theonex » Wed Aug 27, 2014 8:18 am

JRL sorry for the late reply recently i just got very busy. just wanted to say thank you i really appreciate you taking the time to help me sort this out. once again thank you

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