How to deal with an incorrect web page showing up
Moderators: Dorian (MJT support), JRL
How to deal with an incorrect web page showing up
I am having an issue with what happens when a mouse click on the search button in a specific application in a browser doesn't return a positive value (what I was looking for), instead returning some other page, which obviously kills the script.
Is there an If|Then function in Macro Scheduler that will look at the text on a page, preferably in a defined area, and parse it for a certain specific set of text characters, acting in one way if it finds them, continuing on to execute the regular script if not?
Thanks in advance...
Ronen in Zutphen, Netherlands
Is there an If|Then function in Macro Scheduler that will look at the text on a page, preferably in a defined area, and parse it for a certain specific set of text characters, acting in one way if it finds them, continuing on to execute the regular script if not?
Thanks in advance...
Ronen in Zutphen, Netherlands
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Yes, use GetWindowTextEx, and Position and then an If/Else on the result. Or if you're using WebRecorder use the ContainsText function and an If/Else on the result. Or you could use FindImagePos to find something visual. If NumFound is positive it's there otherwise it's not. Or use IfWindowOpen and use the window title, or ... I'm sure there are other things you can do. All of them you can use with an If/Else/Endif.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Options
Hi Galaxyman,
Since it is a browser app, you may want to try out the Web Recorder, it may simplify your script.
If the Web Recorder is not an option, try the Text Capture commands such as GetTextAtPoint or GetTextInRect. These commands do not work for all applications, but I see that they worked on the mjtnet web site with IE6. Verify that these commands work with your brower app.
The Text Capture commands require you know where the text is. I mainly use FindImagePos to locate coordinates on the screen of some icon or label near the text. There are a lot of examples in the forums on how to use it and pitfalls to watch out for. You need tight control over the display properties to keep the scripts simple.
Hope this helps,
Gale
Since it is a browser app, you may want to try out the Web Recorder, it may simplify your script.
If the Web Recorder is not an option, try the Text Capture commands such as GetTextAtPoint or GetTextInRect. These commands do not work for all applications, but I see that they worked on the mjtnet web site with IE6. Verify that these commands work with your brower app.
The Text Capture commands require you know where the text is. I mainly use FindImagePos to locate coordinates on the screen of some icon or label near the text. There are a lot of examples in the forums on how to use it and pitfalls to watch out for. You need tight control over the display properties to keep the scripts simple.
Hope this helps,
Gale
Hi, All,
And thanks for the responses.
First of all, I'm not sure what Web Recorder is.
And then it occurred to me that 90+% of the time at the point my code will break because of an unexpected browser result, it is breaking because there is NO graphic at the point to which I've told my cursor to go, other than whatever background there might be. It seems to me that it might be easier to have some way of doing...
IF>graphic present
//execute normal code
ELSE>
//do something else, then execute normal code
I can't seem to find anything within Macro Scheduler that will do the 'graphic present' thing.
Thanks again for everything...
Ronen
And thanks for the responses.
First of all, I'm not sure what Web Recorder is.
And then it occurred to me that 90+% of the time at the point my code will break because of an unexpected browser result, it is breaking because there is NO graphic at the point to which I've told my cursor to go, other than whatever background there might be. It seems to me that it might be easier to have some way of doing...
IF>graphic present
//execute normal code
ELSE>
//do something else, then execute normal code
I can't seem to find anything within Macro Scheduler that will do the 'graphic present' thing.
Thanks again for everything...
Ronen
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
FindImagePos>........,numFound
If>numFound=0
//No image found - do something
Else
//Do something else
Endif
If>numFound=0
//No image found - do something
Else
//Do something else
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
This is very cool. I understand the idea, but I don't understand what parameters I should be using for the FindImagePos>. I've read the Help on this, but that didn't make it any clearer for me either.mtettmar wrote: FindImagePos>........,numFound
If>numFound=0
//No image found - do something
Else
//Do something else
Endif
I don't know the name of the graphic that is supposed to appear at the particular mouse/screen position, so I can't tell it that. I only know that it will either be a graphic or hyperlinked text. The graphic is what I'm looking for, the hyperlinked text not.
Right now I've got it set up so that my mouse moves to a specific set of coordinates, then it either deals with the graphic that is there or it crashes the macro because there is no graphic and it finds hyperlinked text. I assume I want to start the IF> statement after I've moved the mouse cursor to the position where the graphic is supposed to be.
Thanks again...
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Please read this and all should become clear:
http://www.mjtnet.com/blog/2007/02/20/h ... cognition/
http://www.mjtnet.com/blog/2007/02/20/h ... cognition/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Use the Image Capture Tool
Hi GalaxyMan,
You need to use the Image Capture Tool in the Editor to create a copy of the graphic. You can name it whatever bmp file you want. Probably the easiest place to save it is in your script directory.
To start out capture the graphic and run the script on the same computer using the same display settings. Extra care must be taken when running script on another computer to make sure the display settings are the same.
After you have created your file, often referred to as a "needle" file you look for the the needle in the "haystack" file, usually the entire screen.
Your script should look something like this:
Here is an example:
You may have noticed sometimes I put % around my variables. Usually you can omit them, but use them whenever your script fails to convert the variable name to a value.
Gale
You need to use the Image Capture Tool in the Editor to create a copy of the graphic. You can name it whatever bmp file you want. Probably the easiest place to save it is in your script directory.
To start out capture the graphic and run the script on the same computer using the same display settings. Extra care must be taken when running script on another computer to make sure the display settings are the same.
After you have created your file, often referred to as a "needle" file you look for the the needle in the "haystack" file, usually the entire screen.
Your script should look something like this:
Here is an example:
Code: Select all
//graphic.bmp was created with Image Capture Tool
//graphic.bmp was saved in the script directory
//The color tolerance is 20
//The 1 means return the center of the graphic
//X and Y are arrays, the graphic may appear many times
Let>graphic=%SCRIPT_DIR%\graphic.bmp
FindImagePos>%graphic%,SCREEN,20,1,X,Y,NumFound
if>NumFound>0
MouseMove>X_0,Y_0
LClick
endif
Gale
Okay, a lot to try to digest.
I'm not sure, but does the fact that the graphic that I am looking for is going to be totally different each time make a difference?
I've watched mtettmar's videos SEVERAL times, trying to grok. I think I finally got it. I then looked at Gale's code, which I now understand when I see it, and tried to use that.
The program crashes. Here are the relevant parts of the code that is crashing...
//Capture hyperlink
//Determine if graphic exists
Let>graphic=C:\graphic.bmp
FindImagePos>%graphic%,SCREEN,20,0,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
Endif
BTW: I am using version 10
Thanks again. This is driving me nuts.
I'm not sure, but does the fact that the graphic that I am looking for is going to be totally different each time make a difference?
I've watched mtettmar's videos SEVERAL times, trying to grok. I think I finally got it. I then looked at Gale's code, which I now understand when I see it, and tried to use that.
The program crashes. Here are the relevant parts of the code that is crashing...
//Capture hyperlink
//Determine if graphic exists
Let>graphic=C:\graphic.bmp
FindImagePos>%graphic%,SCREEN,20,0,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
Endif
BTW: I am using version 10
Thanks again. This is driving me nuts.
I found and correct a mistake:
FindImagePos>%graphic%,SCREEN,20,0,X,Y,NumFound
is now:
FindImagePos>%graphic%,SCREEN,20,1,X,Y,NumFound
That was a biggie. The code now runs. Only problem is, the first time it got a return that wasn't a graphic, it displayed the same behavior as previously, acted like it was finding the graphic.
FindImagePos>%graphic%,SCREEN,20,0,X,Y,NumFound
is now:
FindImagePos>%graphic%,SCREEN,20,1,X,Y,NumFound
That was a biggie. The code now runs. Only problem is, the first time it got a return that wasn't a graphic, it displayed the same behavior as previously, acted like it was finding the graphic.
Check for NumFound
After the FindImagePos, check for the value of NumFound. If it is greater than 1 the script may have found multiple areas of the screen that looked like the graphic. If you do not see multiple graphics, try reducing the color tolerance until NumFound is 1.
You also mentioned the graphic is sometimes not present. We should be using the if/else logic (or multiple if statements if you want to handle all the possible values (-1, 0, 1, >1)
The -1 value occurs if there is a syntax problem or the script cannot find open the graphic.bmp file.
Another thing you mentioned is that the graphic you are looking for will look totally different each time. Yes that will make a big difference.
Is graphic's appearance totally unpredictable or is it one of several images that are possible?
Is there another static graphic (a border, some text like "picture of the day") that can be used to locate the varying graphic?
Gale
You also mentioned the graphic is sometimes not present. We should be using the if/else logic (or multiple if statements if you want to handle all the possible values (-1, 0, 1, >1)
The -1 value occurs if there is a syntax problem or the script cannot find open the graphic.bmp file.
Another thing you mentioned is that the graphic you are looking for will look totally different each time. Yes that will make a big difference.
Is graphic's appearance totally unpredictable or is it one of several images that are possible?
Is there another static graphic (a border, some text like "picture of the day") that can be used to locate the varying graphic?
Gale
Any of the other suggestions work?
Hi GalaxyMan,
Hope you are not trying to get past a security graphic.
If the graphic itself is unpredictable, is there anything else on the screen that points to it? Is it always next to some other graphic or text? If there is you can do an add an offset to the coordinates to click on the unpredictable graphic.
Is the graphic predictable in some other way. For example, does it always contain some colors seen nowhere else on the screen?
Gale
Hope you are not trying to get past a security graphic.
If the graphic itself is unpredictable, is there anything else on the screen that points to it? Is it always next to some other graphic or text? If there is you can do an add an offset to the coordinates to click on the unpredictable graphic.
Is the graphic predictable in some other way. For example, does it always contain some colors seen nowhere else on the screen?
Gale
Hi, Gale.
No, no security anything. If you go to the URL below and use R3026676 as your search parameter for MLS#, you'll see exactly what it is I'm dealing with. It will be the smaller graphic in the center, of a home.
http://illustrated.leadmaxx.lantrax.com ... ion=Search
That is the normal result that I am looking for. If you want to see a non-return which causes my script to crash, search for F1012525.
Thanks again for sharing your brain...
No, no security anything. If you go to the URL below and use R3026676 as your search parameter for MLS#, you'll see exactly what it is I'm dealing with. It will be the smaller graphic in the center, of a home.
http://illustrated.leadmaxx.lantrax.com ... ion=Search
That is the normal result that I am looking for. If you want to see a non-return which causes my script to crash, search for F1012525.
Thanks again for sharing your brain...