Read one line, enter it into a webfield, read the next...

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

a2a
Newbie
Posts: 13
Joined: Fri Jul 16, 2010 5:06 pm

Read one line, enter it into a webfield, read the next...

Post by a2a » Fri Jul 16, 2010 5:12 pm

Hey, thanks a lot for reading :)

Im a newbie into this and im wondering how (because im sure it is? :P ) to read one line from a .txt file, enter it into a webfield, click OK, then, read line two, enter it, ok ... etc. etc. untill there are no more lines.

Any ideas ?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jul 16, 2010 7:03 pm

Automating web stuff is a little more challenging than a standard desktop application, because the web site design can change at any time (you have no control over this usually unless you are the web developer also).

If the webpage is really simple, you could automate the data entry
with mouse movements and simulated keyboard inputs.

If the page is more complex, requiring scrolling, needing to make decisions, etc, then it is better to script the IE browser object inside of macro scheduler. There are many examples of this on the forum and in the standard examples which were most likely installed by default. This does require you to know some HTML and web development terminology. This is much more like programming than the previous solution.

Depending upon the web page and what you are trying to do, sometimes it's also possible to use the HTTPRequest command in macro scheduler to do what's called a HTTP Post and send the data directly to the web application. This doesn't require a browser to be open or scripted. But does require you to know HTML concepts and terminology. You will be responsible for examining the pure HTML of web pages and figuring out what the variable names are, etc to be successful at this.

a2a
Newbie
Posts: 13
Joined: Fri Jul 16, 2010 5:06 pm

Post by a2a » Fri Jul 16, 2010 7:26 pm

I am extremly happy for your quick and really in-depth response here, thanks a lot! i tend to see you amongst my forum searches aswell as the top replier :P


I do understand it will be something like this; written by Marcus Tettmar
from http://www.mjtnet.com/blog/2007/07/02/r ... in-memory/

Let>k=1
Label>start
ReadLn>c:\\\temp\\\test.txt,k,line
If>line=##EOF##,finish
MessageModal>line
Let>k=k+1
Goto>start
Label>finish

But im not sure how to fit it into my simple script..

1. goto google.com
2. read line1
3. enter it into the searchfield
4. click search
5. repeat



Here is my script:

MouseMove>0,0
Let>delay=1
IE_Create>0,IE[0]

IE_Navigate>%IE[0]%,http://google.com/,r
IE_Wait>%IE[0]%,r
Wait>delay

IE_Wait>%IE[0]%,r
Wait>delay

Let>FrameName={""}
Let>FormName={"f"}
Let>FieldName={"q"}
Let>FieldValue={"hey hey"}
IE_FormFill>%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0,r

Let>FrameName={""}
Let>FormName={"f"}
Let>TagValue={"btnG"}
IE_ClickTag>%IE[0]%,str:FrameName,str:FormName,INPUT,NAME,str:TagValue,r

IE_Wait>%IE[0]%,r
Wait>delay

Label>end_script

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jul 16, 2010 8:04 pm

1. goto google.com
2. read line1
3. enter it into the searchfield
4. click search
5. repeat
What do you want to do with the results which are returned after clicking "search"?

If you only want to do google searches, then it is very easy to construct a URL and send this to google using HTTPRequest like so:

Code: Select all

Let>page=http://www.google.com/search?h1=en&source=hp&q=
Let>searchterm=macroscheduler
Let>searchpage=%page%%searchterm%
HTTPRequest>searchpage,,GET,,result
MessageModal>result

You could save the result directly to a text file and then open this file in the browser if you wanted.... depends upon what you want to do with the results.

Simply replace the variable "searchterm" with each line of input from your text file. It could need URL encoding if it contains certain special characters or spaces (easy to do in VBScript).

a2a
Newbie
Posts: 13
Joined: Fri Jul 16, 2010 5:06 pm

Post by a2a » Fri Jul 16, 2010 8:15 pm

i see, i kind of wanted it to be really human though. And for it to handle sessions and things, even at a later stage implement the Screencapture command to screenshot the HTML result page one gets after a search,

by the way, the result from i.ex line1 from my test.txt, if i want that to be instead of my example ("hey hey"), it will be my replacing it with %line% ?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jul 16, 2010 8:22 pm

by the way, the result from i.ex line1 from my test.txt, if i want that to be instead of my example ("hey hey"), it will be my replacing it with %line% ?
Yes.

a2a
Newbie
Posts: 13
Joined: Fri Jul 16, 2010 5:06 pm

Post by a2a » Fri Jul 16, 2010 8:26 pm

Code: Select all

MouseMove>0,0 

Let>k=1 
Label>start 
ReadLn>c:\\\temp\\\test.txt,k,line 
If>line=##EOF##,finish 
MessageModal>line 
Let>k=k+1 
Goto>start 
Label>finish


Let>delay=1 
IE_Create>0,IE[0] 

IE_Navigate>%IE[0]%,http://google.com/,r 
IE_Wait>%IE[0]%,r 
Wait>delay 

IE_Wait>%IE[0]%,r 
Wait>delay 

Let>FrameName={""} 
Let>FormName={"f"} 
Let>FieldName={"q"} 
Let>FieldValue={"%line%"} 
IE_FormFill>%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0,r 

Let>FrameName={""} 
Let>FormName={"f"} 
Let>TagValue={"btnG"} 
IE_ClickTag>%IE[0]%,str:FrameName,str:FormName,INPUT,NAME,str:TagValue,r 

IE_Wait>%IE[0]%,r 
Wait>delay 

Label>end_script

Okay there it is ...
On Debug - Run, it gives me an error on line 1 already :P Invalid numeric value .

Edit: i know i have the correct script based off the other article, but to get that to understand it needs run MY macro process over and over untill it is done is harder ...

Im not looking for results right away, i can setup a listener on the other side to see if its working like i need it to, the key here would be to get this part working, then using this puppy to screenshot the result, like if it was an IE window:

Code: Select all


Wait>3.5

GetScreenRes>sX,sY
Min>min
Sec>sec
Hour>hour

ScreenCapture>0,0,sX,sY,c:\temp\cap.%hour%.%min%.%sec%.jpg


Last edited by a2a on Fri Jul 16, 2010 8:37 pm, edited 2 times in total.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jul 16, 2010 8:29 pm

There are lots of trailing spaces in your code. Do Edit -->Remove Trailing Spaces from the code editor.

When I deleted the trailing space from MouseMove>0,0
I got no error.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jul 16, 2010 8:31 pm

ReadLn>c:\\\temp\\\test.txt,k,line
Why so many backslashes? I think this is a problem.

a2a
Newbie
Posts: 13
Joined: Fri Jul 16, 2010 5:06 pm

Post by a2a » Fri Jul 16, 2010 8:36 pm

adroege wrote:
ReadLn>c:\\\temp\\\test.txt,k,line
Why so many backslashes? I think this is a problem.
Thanks again, testing it out, its got a lot of backlashes just because the original aricle has:
http://www.mjtnet.com/blog/2007/07/02/r ... in-memory/

I did an edit on my last post and filled in my vision too. sorry for the confusion here ...

a2a
Newbie
Posts: 13
Joined: Fri Jul 16, 2010 5:06 pm

Post by a2a » Fri Jul 16, 2010 8:52 pm

I have tried a lot of combinations now regarding those slashes, all of them result in a ##NOFILE## in the debugger. tryine more now ..

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jul 16, 2010 8:58 pm

Code: Select all

ReadLn>c:\temp\test.txt,k,line 
Normally a file path has just one backslash separating
folder names like so.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jul 16, 2010 9:02 pm

Change

Let>FieldValue={"%line%"}

to

Let>FieldValue={%line%}


Also

Move the line which says:

Goto>start

Down to the bottom of the script, since that is what makes
the script repeat.

Also

Move the line which says:

Label>finish

To the bottom of the script also

a2a
Newbie
Posts: 13
Joined: Fri Jul 16, 2010 5:06 pm

Post by a2a » Fri Jul 16, 2010 9:23 pm

Seems to be rocking it GOOD!! Thank you a lot for guiding me. In the end i now see it all has the same structure as good ol .BAT scripting (atleast with the labels and goto`s :P)

Full code again, WITH the screencap:

Code: Select all

MouseMove>0,0
Let>k=1
Label>start
ReadLn>C:\temp\test.txt,k,line
If>line=##EOF##,finish
MessageModal>line
Let>k=k+1

Let>delay=1
IE_Create>0,IE[0]

IE_Navigate>%IE[0]%,http://google.com/,r
IE_Wait>%IE[0]%,r
Wait>delay

IE_Wait>%IE[0]%,r
Wait>delay

Let>FrameName={""}
Let>FormName={"f"}
Let>FieldName={"q"}
Let>FieldValue={%line%}
IE_FormFill>%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0,r

Let>FrameName={""}
Let>FormName={"f"}
Let>TagValue={"btnG"}
IE_ClickTag>%IE[0]%,str:FrameName,str:FormName,INPUT,NAME,str:TagValue,r

IE_Wait>%IE[0]%,r
Wait>delay

Wait>10

GetScreenRes>sX,sY
Min>min
Sec>sec
Hour>hour

ScreenCapture>0,0,sX,sY,c:\temp\cap.%hour%.%min%.%sec%.jpg

Label>finish

Goto>start


It works!, but i think i have gotten a wrong impression about what that screencap actually does :P i was hoping for it to show me what the Webpage would show haha. If thats not posible (no actuall window to capture), what was that you told about getting results to a .txt ? in .html perhaps so one could just rename and view the results locally ?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jul 16, 2010 9:45 pm

Label>finish
Goto>start


Swap those two statements
like so:


Goto>start
Label>finish

Otherwise when there are no more lines to read in the text file
it goes to finish, and then goes back to start - repeating the
entire process in an infinite loop.

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