How to deal with an incorrect web page showing up

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Use the "Photo" column header

Post by gdyvig » Thu Jul 09, 2009 4:17 pm

Hi GalaxyMan,

For the first MLS I got a screen with a label "Photo" white font with a black background and the photo of the house below it.

For the second MSL I got a screen with the same URL where both the "Photo" label and the photo of a house were missing. In its place was a text message "Your search didn't return any results".

If that is the only possible error message you could check for it using the text command you tried earlier.

Or you can check for the "Photo" label not displaying.

Code: Select all

//PhotoLabel is the white on black column heading
Let>PhotoLabel=%SCRIPT_DIR%\PhotoLabel.bmp
FindImagePos>%PhotoLabel%,SCREEN,20,1,X,Y,NumFound

If>NumFound=1
  //Add about 50 pixels to the Y coordinate to where the photo is
 //MouseMove>X_0,Y_0+50    (bad syntax, thanks JRL)
 MouseMove>X_0,{%Y_0%+50}
 LClick
Else 
 //Put your error code here
 //NumFound comments added in response to JRL's post.
 //NumFound=-1 means syntax error
 //NumFound=0 means no images found
 //NumFound>0 means many images found - which one is good?
 //                    usually the first one, but sometimes not.
 //Perhaps read the screen text
 //Or do a ScreenCapture
Endif
Last edited by gdyvig on Thu Jul 09, 2009 8:42 pm, edited 1 time in total.

User avatar
GalaxyMan
Junior Coder
Posts: 40
Joined: Sat Jun 27, 2009 7:21 pm

Post by GalaxyMan » Thu Jul 09, 2009 6:01 pm

What a nice idea! Makes such sense, too. So I tried this -- here's the code I used:

//Finding the photo label
SetFocus>Firefox*
Let>PhotoLabel=C:\PhotoLabel.bmp
FindImagePos>C:\PhotoLabel.bmp,SCREEN,20,1,X,Y,NumFound

If>numFound=1
//Add ~ 50px to the Y coordinate to find the photo
MouseMove>X_0,Y_+50
RClick
Endif

I did the whole screen capture thing of the Photo header as a bitmap. Nothing happened. It gave me my browser and then nothing. The mouse never moved. ***Scratching head***

The reason I use the RClick is because the next thing I'm going to do is to save/copy the URL that the photo is pointing/hyperlinked to.

Thanks again...

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Image Capture Tool or ScreenCapture command?

Post by gdyvig » Thu Jul 09, 2009 6:57 pm

You said:
I did the whole screen capture thing of the Photo header as a bitmap. Nothing happened. It gave me my browser and then nothing. The mouse never moved. ***Scratching head***
Were you referring to the Image Capture Tool or the ScreenCapture command?

There was a fix to the Image Capture Tool a couple of releases ago. If you don't have the latest, try updating. If you do have the latest, try reinstalling. I find the tool works best if I click on the upper left of the screen area I want to capture and drag down to the lower right. Doing the reverse sometimes fails.

If the problem is with the ScreenCapture command, be sure to include the file extension. Use jpg for smaller files sizes. This code will capture the entire window to be used when photo does not display:

Code: Select all

Let>MLS_Error=%TEMP_DIR%\Error_%MSL%.jpg
GetWindowSize>Program Manager*,nWidth,nHeight
ScreenCapture>0,0,%nWidth%,%nHeight%,%MLS_Error%
Were you able to capture the URL link OK when the photo was there?


Gale


Gale

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

Post by JRL » Thu Jul 09, 2009 8:06 pm

...The mouse never moved. ***Scratching head***
The syntax for MouseMove> is incorrect. Also changed your "If>numFound" line.

Try this:

/Finding the photo label
SetFocus>Firefox*
Let>PhotoLabel=C:\PhotoLabel.bmp
FindImagePos>C:\PhotoLabel.bmp,SCREEN,20,1,X,Y,NumFound

If>numFound>0
//Add ~ 50px to the Y coordinate to find the photo
Add>Y_0,50
MouseMove>X_0,Y_0
RClick
Endif

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Need complex expression to MouseMove to offset in one line.

Post by gdyvig » Thu Jul 09, 2009 8:33 pm

I forgot about the inability of MouseMove to accept calculations. I'll go back and fix my original post.

Here is another way using a complex expression:

Code: Select all

MouseMove>X_0,{%Y_0%+50}
As to whether whether to use "If>NumFound=1" or "If>NumFound>0", that depends on whether you want to treat extra found images as a possible error condition or a situation that is usually safe to ignore.


Gale

User avatar
GalaxyMan
Junior Coder
Posts: 40
Joined: Sat Jun 27, 2009 7:21 pm

Post by GalaxyMan » Fri Jul 10, 2009 6:46 am

Hi, Gale.

I seem to be having an attack of the thicks... :?

Here is the code, trying to incorporate your suggestions. The mouse still never moves...

//Finding the photo label
SetFocus>Firefox*
Let>PhotoLabel=C:\PhotoLabel.bmp
FindImagePos>C:\PhotoLabel.bmp,SCREEN,20,1,X,Y,NumFound

If>numFound=0
//Add ~ 50px to the Y coordinate to find the photo
MouseMove>X_0,{%Y_0%+50}
RClick

Endif

I also tried this without the 'complex' expression and used the

Add>Y_0,50
MouseMove>X_0,Y_0

and got the same non-result.

I've been using the Screen Capture command to get the PhotoLabel.bmp file. I'm not sure that I've seen/found the Image Capture Tool. When I click on FindImagePos, it opens a Code Builder dialog with a Capture button in the upper right-hand corner, upon which I click. It then takes me to an Image Capture dialog which has two menu choices, File & Capture. I choose Capture and it takes me to a menu of choices of what to capture. I choose Screen Area. I then isolate the area (PhotoLabel) that I want to use and save it as PhotoLabel.bmp, which seems to be the default format. Does it being a .bmp as opposed to a .jpg make a difference in this?

I deliberately put it in the root C:\ directory to make the syntax simpler. Does it matter how many levels down into the directory tree I place my files?

I haven't yet checked out the MLS Error code yet, as I can't get to that point with what I have. But I love the idea. Do I understand it correctly that it's only to capture the screen when I don't get a PhotoLabel return to my search?

I'm also not sure what you mean by the following with respect to what I'm trying to do...

As to whether whether to use "If>NumFound=1" or "If>NumFound>0", that depends on whether you want to treat extra found images as a possible error condition or a situation that is usually safe to ignore.

Thanks again,

Ronen

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

Post by JRL » Fri Jul 10, 2009 1:34 pm

You've now changed

If>numFound>0

to

If>numFound=0

If "numfound" is zero then the image was not found so there are no coordinates for the MouseMove> function to work with. Try setting it back to:

If>numFound=1

or

If>numFound>0
As to whether whether to use "If>NumFound=1" or "If>NumFound>0", that depends on whether you want to treat extra found images as a possible error condition or a situation that is usually safe to ignore.
When you use FindImagePos> it will find every copy of the needle file it finds in the haystack file. There might be more than one. For that reason, to prevent a failure of your code if the possibility existed that more than one was found, I suggested using the greater than. Gale's point is that since you are pressing a specific button, technically, finding more than one is a potential failure. My feeling is that at this point do what is most likely to get the code working then deal with potential failures later.

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Fri Jul 10, 2009 3:08 pm

Hi Ronen,

JRL covered the NumFound issue very nicely. I will cover the other questions.
I've been using the Screen Capture command to get the PhotoLabel.bmp file. I'm not sure that I've seen/found the Image Capture Tool. When I click on FindImagePos, it opens a Code Builder dialog with a Capture button in the upper right-hand corner, upon which I click.
Yes, you found the Image Capture Tool. You can also access from the menu at the top of the editor: Tools>Image Capture Tool.
I then isolate the area (PhotoLabel) that I want to use and save it as PhotoLabel.bmp, which seems to be the default format. Does it being a .bmp as opposed to a .jpg make a difference in this?
Yes, the Image Capture Tool restricts you to bmp files, I forgot that was the case.

Yes it does make a difference whether you use a bmp or a jpg. A jpg image may have a slightly different appearance and be incompatible with the FindImagePos command. So always use the Image Capture Tool, not some other third party capture tool to be safe.
I deliberately put it in the root C:\ directory to make the syntax simpler. Does it matter how many levels down into the directory tree I place my files?
I think there is a limit, not sure if it is the number of levels or the number of characters. Some of my stuff is nested quite deeply, so it should not be a problem if you keep your folder names short.
I haven't yet checked out the MLS Error code yet, as I can't get to that point with what I have. But I love the idea. Do I understand it correctly that it's only to capture the screen when I don't get a PhotoLabel return to my search?
Yes, that is the purpose of the screen capture. To help you figure out what went wrong.

As you get deeper into your script you may find more error situations. For example, you may find the PhotoLabel but no photo or URL link below it when no photo is available.

Gale

User avatar
GalaxyMan
Junior Coder
Posts: 40
Joined: Sat Jun 27, 2009 7:21 pm

Post by GalaxyMan » Fri Jul 10, 2009 3:42 pm

JRL wrote:You've now changed

If>numFound>0

to

If>numFound=0

If "numfound" is zero then the image was not found so there are no coordinates for the MouseMove> function to work with. Try setting it back to:

If>numFound=1

or

If>numFound>0
Oh, I do hate those innocuous little typos. Must pay more attention to the details...

This works GREAT!!!

I made a minor adjustment to the X & Y coordinates to make sure the cursor was dead center on the graphic position. Now I get to see what I can do utilizing this.

Can't thank everyone enough. But have no fear, I'll be back...
8)

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