simple script eating all my cpu & logging into hotmail

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
brunop
Junior Coder
Posts: 38
Joined: Mon Dec 03, 2007 2:29 pm

simple script eating all my cpu & logging into hotmail

Post by brunop » Mon Dec 03, 2007 3:04 pm

Hello

im quite new to this but i can see how this tool could potentially make my life a whole lot easier so im really interested in learning!

i have 2 projects that im working on at the moment and im stuck in both
:-)

first i want to make an automation for a program that keeps getting a error message. this message only pops up around every 20 min. and it stops the program from running, as soon as there has been a click on the error, the program continues to run.

so my approach to this was to use waitscreenimage> and the add on image recognition software also provided on this page, to capture a screenshot of the error for the waitscreenimage to compare with.


but the problem is that when i start running this script (that seems to work) it eats all my cpu power. i guess it is because it searches the screen over and over really fast. is it possible to have the script search eg. once pr minute and would that make the script much lighter on the cpu?
would it also be possible to build in a way to stop the script after having clicked the error message away eg. 5 times? or is there a completely different approach to this that i have not thought of?

i was also thinking of a way to use waitwindowopen> but i have no clue how to tell the program to look for this error. the error does not show in the windows "toolbar" (the one in the bottom, between start and the clock :roll: )

let me know what you think



on top of this already long description i will bother you with my other problem.

im trying to create a script that opens several hotmail accounts, but i have run into a problem.

Im trying to use the web automation tool and everything seems to work well untill i want to open another window to login to the next hotmail account. as soon as the script types in http://www.hotmail.com it is not sent to the login page but it is sent directly into the previously opened hotmail account so that i now have two windows showing the same hotmail account. when i try to replicate this myself by firstly logging into one account and then opening a new window and typing http://www.hotmail.com i am sent to the correct login screen.
So it would seem that the bot is doing something else than i am.
When recoding i am doing all steps exactly the same as when im logging in without the automation tool but the outcome is different.

Maybe there is a good way to do this without using the automation tool. all i really want to do is to open http://www.hotmail.com, put in my personal info and open a new window and do the same again.



hopefully i did not loose everyone on the way to the bottom of this long post.


Hope to get my scripting career kickstarted with some good input from you guys.

Kindly

Bruno

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

Post by Marcus Tettmar » Mon Dec 03, 2007 3:10 pm

Much easier if you could post each problem in a separate post.

Problem 1:

Do you really need to use WaitScreenImage to dismiss a message box? Ideally you can just use the window functions and watch for the window title. If so you actually just need to create a macro to dismiss it and create a window event schedule under Macro Properties > Run When > Advanced. Or use OnEvent.

If you really must use WaitScreenImage the answer to your question is to make your OWN version of WaitScreenImage with the FindImagePos command in a loop with a delay you can set to whatever you like. If you only want to check once per minute you don't even need a loop. Use FindImagePos to see if the image is on the screen and if so click it. Simply set up a repeating schedule for this macro to repeat once per minute. So you'd end up with NO loop.

Problem 2:

If you are using WebRecorder, you must be using the Navigate function to navigator to http://www.hotmail.com. Navigate takes as one of it's parameters an IE instance variable, created by a call to CreateIE. If you always pass the same variable then, sure, Navigate will always navigate to that page in the same instance of IE. If you use CreateIE to create a NEW IE instance and pass THIS value to Navigate then you will instead navigate to hotmail in the NEW instance.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

brunop
Junior Coder
Posts: 38
Joined: Mon Dec 03, 2007 2:29 pm

Post by brunop » Mon Dec 03, 2007 4:59 pm

Hello

thanks for the very quick reply!

i do not need to use waitscreenimage it was just the best i could come up with. I am not sure how i can watch for the window title and find its name since the error message does not show in the taskbar as a seperate title nor does it show as a process in the alt-ctrl-del joblist.
since the error shows at random intervals i cannot use a timer either.

if i somehow could get the window name of the error it would be much easier. Will this approach use a lot of CPU power?


problem 2

i type in http://www.hotmail.com in the top and is sent to hotmail. here i login so i can see my first mail account in the window. then i press the new button in the top and i get a new blank window where i go to hotmail.com and log in with my other account. then when i try to play the macro i get the situation where it logs into the first fine but when opening the new window it is sent directly to my first mail account and not to the login screen.

ill get back to you as soon as i have testet your other suggestions
Last edited by brunop on Mon Dec 03, 2007 5:15 pm, edited 1 time in total.

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

Post by Marcus Tettmar » Mon Dec 03, 2007 5:05 pm

Can you send a screen shot of the "error message"? All windows have titles. Am curious as to what this error message looks like. Might be able to give you some ideas.

None of the methods I proposed use much cpu power.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

brunop
Junior Coder
Posts: 38
Joined: Mon Dec 03, 2007 2:29 pm

Post by brunop » Mon Dec 03, 2007 5:37 pm

Well i dont know if this qualifies as a "window" it has an ok button but is created by this software and not by windows - where do you want me to send the screenshot?

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

Post by Marcus Tettmar » Mon Dec 03, 2007 5:48 pm

Send to support AT mjtnet.com
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

brunop
Junior Coder
Posts: 38
Joined: Mon Dec 03, 2007 2:29 pm

Post by brunop » Mon Dec 03, 2007 6:59 pm

ok we established that it was not a window so ill have to go for FindImagePos .

now im struggling with that instead :-)

well for the script to know what it should look for i have taken a screenshot of the "ok" button from the error message(c:\button.bmp). the top left coordinates of the img is: 664,584 and the bottom right is 730,615

so if i want to get the script to look for that button i would start out with


GetScreenRes>X,Y (not really sure what this is good for)

then go on to

ScreenCapture>664,584,730,615,c:\button.bmp

this captures the area where the button will appear.


FindImagePos>d:\today_button.bmp,d:\screen.bmp,0,1,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
Endif

im getting in over my head here. can you please point me in the right direction. been trying to work from the help-file but im kinda lost

after all this i need to get it to either run the routine again (if the button is not found) or to click the button if it is found - here i have no clue either


this is hard!

Bruno

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

Post by Marcus Tettmar » Mon Dec 03, 2007 7:27 pm

It's much easier than that. There are examples in the help file.

1) Capture the ok button to a bmp file. Be sure to use the Image Capture Tool in Macro Scheduler. The Image Capture tool is in the Advanced Editor and also available from the FindImagePos command builder dialog.

2) Let's assume you've saved this bmp to c:\okbtn.bmp

3) Try this code:

FindImagePos>c:\okbtn.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
LClick
Endif

This code will click in the middle of the OK button when it finds it. It will do nothing if it does not find it.

You could schedule this to happen once a minute under the Run When tab of Macro Properties.

If the ok button is not unique - if there are other buttons that look the same on the screen - then you'll have to look for the whole messag "window", or some other part of it. This would also mean you'd have to take that into consideration when determining the coordinates of the OK button. But you may not need to LClick on the ok button, you may only need to "Press Enter".
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

brunop
Junior Coder
Posts: 38
Joined: Mon Dec 03, 2007 2:29 pm

Post by brunop » Mon Dec 03, 2007 10:19 pm

ok iv created a script that contained the code you gave me and then i tried to add a few things that i want the script to do afterwards (just a few mouseclicks here and there)

now it seems as it is running the complete script no matter that the ok button is not showing on the screen (there is nothing that looks like it either) . i thought it would only run the next lines of code after "your suggestion" when it found the ok button.

am i missing something here .. again

Bruno

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

Post by Marcus Tettmar » Mon Dec 03, 2007 10:45 pm

Hope this will help:

Code: Select all

FindImagePos>c:\okbtn.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
   ..
   ..
   .. ALL CODE IN HERE BETWEEN IF AND ELSE WILL
   .. BE EXECUTED WHEN THE IMAGE *IS* FOUND
   ..
Else
  ..
  .. ANY CODE HERE BETWEEN ELSE AND ENDIF WILL
  .. ONLY BE EXECUTED IF THE IMAGE IS *NOT* FOUND
  ..
Endif

ALL HERE WILL *ALWAYS* BE EXECUTED
The Else part is optional. My previous example had no Else part.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

brunop
Junior Coder
Posts: 38
Joined: Mon Dec 03, 2007 2:29 pm

Post by brunop » Tue Dec 04, 2007 11:12 pm

Hey

I just wanted to thank you for your help throughout yesterday, everything is running like a dream now. ill just have to tweak it a bit then im good to go!

Bruno

brunop
Junior Coder
Posts: 38
Joined: Mon Dec 03, 2007 2:29 pm

Post by brunop » Fri Dec 07, 2007 5:19 pm

Hmm got one more question


is it possible to make it so that if findimagepos has not found the image it is looking for within a certain timeframe then it should do something else, like exit a program

Bruno

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

Post by Marcus Tettmar » Fri Dec 07, 2007 5:24 pm

Yes, easiest way to check elapsed time is with VBScript's Timer function. Search the forums for Timer and you should find some examples. There's also an example here in this load testing doc:
http://www.mjtnet.com/loadtesting.pdf
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