How can I perform mouse click based on image type?

Here is what I wanted to do in brief… Based on what it shows I have to click at that location…

if the image with text ‘correct 1’ shows up then click at (512,320)
if the image with text ‘correct 2’ shows up then click at (612,370)
if the image with text ‘correct 3’ shows up then click at (712,456)

Only one answer is possible at a time.

I have to repeat this for 40 times…

Here is what I did…

  1. Saved 3 images ‘correct 1’ , ‘correct 2’, ‘correct 3’
  2. I do not know how to compare images?

Please help me…

You almost wrote the script already. :slight_smile:

Try this:

if imageFound("correct 1") then
	click (512,320) 
else if imageFound("correct 2") then
	click (612,370) 
else if imageFound("correct 3") then
	click (712,456) 
	LogError "None of the correct images was found"
end if

Infact I also wrote similar script. It works but not quite really. Some more facts…

  1. I actually mentioned about 3 images. But I have infact 10 images

  2. The way it currently works is that the script is very slow if ‘correct 10’ image is found. What I see is that it is typing 9 times "Image not found’ because it is checking each condition.

  3. Please note that ours is time sensitive gaming application. Meaning, a human can perform maximum 40 clicks in 10 minutes where as the above script does ~15 clicks in 10 minutes…

The kind of solution I am looking is …

possible images: {‘correct 1’, ‘correct 2’,‘correct 3’,‘correct 4’,…‘correct 10’,}

if ‘correct 10’ shows up then it should read it from the above list and then click (712,345) that’s it. That way, we can perform maximum possible clicks within that 10 minutes.

if …else login takes time when the number is too high…

Okay, so the problem is that it’s too slow because Eggplant takes a long time searching for each image before it gives up and moves on to look for the next one. There are several things you can do to speed up the searching.

First, if we can assume that the image you are looking for is already showing on the screen (so there’s no need for Eggplant to wait for it to appear and retry its search like it usually does) you can specify a time of 0 on the imageFound() function, like this:

 if imageFound(0,"correct 1") then...

That may be enough to fix the problem in itself, since otherwise Eggplant will be searching the screen multiple times waiting for the first image to appear, before it begins looking for the next one. But there’s more you can do.

You can also set the searchRectangle to limit the area of the screen where Eggplant looks for the image. Since you know where the image will be shown (at least approximately), you can prevent Eggplant from searching the entire screen by doing this at the beginning of this section of your script:

set the searchRectangle to correctImageRect

You’ll have to set correctImageRect appropriately first, of course. At the end of that section, be sure to set the searchRectangle back again so Eggplant will search the entire screen:

set the searchRectangle to empty -- search the full screen again

This approach will speed up each search considerably.

Finally, you can simplify the script by looking for all of the images with a single call and then checking to see which one was found, like this:

if imageFound(0,"correct 1", "correct 2", "correct 3") then
    set correctNumber to foundImageNumber()
    click item correctNumber of ((512,320), (612,370), (712,456))
    LogError "None of the correct images was found"
end if

Adapt the above for your additional images and locations. You could use the foundImageName() or foundImageInfo() function instead of foundImageNumber(), depending on how you want to structure the script. Any of these functions (as well as foundImageLocation(), which probably wouldn’t be useful in your case) return information about the last image that was found, which is particularly useful after looking for several images at once like this.

Hopefully this will be enough to get your script working the way you want!