How to retrieve image hot spot at runtime

Hi All,

How do I retrieve image hot spot at runtime.

if not imageFound(image) then
retrieve image hot spot…
end if

It’s pretty much like you wrote it:

put imageHotSpot(image)

I want to be sure that the image hot spot is really what you’re looking for though. The Hot Spot is a coordinate within the captured image and has no relation to the pixels on the remote screen. You can retrieve the coordinates on the remote screen where the image was originally captured, which I think might be what you are looking for:

put imageInfo(image)'s CaptureLocation

Hope this helps.

Matt,

I’ve tried but they are returned me differenct coordinator as below.

When I run command Click “testimage”, it shows (235,214) from the output window. I also make sure this coordinator is corrected by run Click (235,214).

put imageinfo(testimage) into mycoord
put mycoord. It returned me (199,58)

put imagehotspot(testimage) into mycoord
put mycoord. It returned me (36,165).

Could you please explain to me how this happen? Did I do something wrong.

Thanks so much for your help.

In your original example, you were asking for a coordinate from an image that was not found on the screen:

if not imageFound(image) then
retrieve image hot spot…
end if
This is different from the example you are now asking about.

In your new example, the value that you want is (I think) foundImageLocation() or, perhaps just imageLocation(). FoundImageLocation() returns the coordinates of the hot spot on screen as returned by a previous command. This is commonly used in this way:

if imageFound("someImage") then 
 ? ? ?Click foundImageLocation() 
 end if 

 waitForAny 10, "Save Button", "Replace Button" 
 Click foundImageLocation()

In the first example, foundImageLocation() saves you from having to search for the same image again in order to click it. In the second example, it also saves you from having to figure out which image was found.

ImageLocation(“image”) searches for the specified image and returns the coordinates at which the hotspot would be located. This is often used when specifying search rectangles:

put imageLocation("Close button") into upperLeftCorner 
 put imageLocation("Resize tab") into lowerRightCorner 
 setSearchRectangle ( upperLeftCorner, lowerRightCorner)

Going back to my previous post, the Hot Spot is defined as a coordinate relative to the upper-left corner of the captured image. So if you have an image that is 10 pixels by 10 pixels with the Hot Spot in the middle, the Hot Spot’s value is (5, 5) relative to the upper-left corner of the image and this doesn’t change. So it doesn’t matter where the image is found on the screen; imageHotSpot() always returns the same value.

The other option I gave,

imageInfo()'s CaptureLocation

returns the coordinates on the screen where the upper-left corner of the image (not the Hot Spot) was located when it was originally captured. This value is fixed at the time of capture and never changes. It may or may not correspond to where the image is found on the screen when you run your script. If you want to take a chance on the captured element being in the same location when the script is run, you can use this value and the Hot Spot to try to target the element:

if not imageFound("myImage") then 
 ? ? Click imageInfo("myImage")'s captureLocation + imageHotSpot("myImage") 
 else 
 ? ? ?click foundImageLocation() 
 end if

I hope this clarifies the situation for you.

Regards,
Matt