Forcing mouse click

Hi All,

Is there anyway that I could set specific area to capture and force a mouse click on that area at runtime? If you could provide sample code, I’m very appreciated.

Best Regards,

I’m not entirely sure I understand what you’re trying to do, but it is possible both to capture a specific area of the screen and to send a mouse click to specific coordinates.

To capture a specific area of the screen, you just use the capturescreen command with the necessary parameters:

capturescreen (name: "someScreen", rectangle:(x, y, x, y) )

or just

capturescreen "someScreen", (x, y, x, y)

You can specify the rectangle with specific coordinates as above, or you can define the area to capture with the locations of other images. There is a suite of functions available at http://www.redstonesoftware.com/phpbb2/viewtopic.php?t=87 that will return the coordinates of a rectangle based on the location of one or more images. So the above could also look something like this:

capturescreen "someScreen", betweenVertically("upperimage", "lowerimage")

or

capturescreen "someScreen", aboveAndToTheRightOf("someimage")

Clicking the mouse at specific coordinates is even easier:

Click (324, 57) // where x=324 and y=57

Most of the commands that take images as targets will also accept coordinates (a notable exception is WaitFor).

You can also capture a specific area of the screen and then use that image as the target for a click – this is the most involved scenario and I’ll only go into it if that’s really what you are asking for.

Let us know if this doesn’t address the scenario that you had in mind.

Regards,
Matt

Matt,

Yes, here is what I want.
I already captured all of images, and using these images as target to click; however, in case if the images not found, I’d like to capture image on screen again which will replace the old image. Then using this new image as target to click.

Thanks so much for your time.

Best Regards,

I could tell you how to do this, but since the approach you’re taking is basically to assume that the element you want to target is still in the same place as it was originally, you’d be better off doing this:

Click (imageInfo("myImage").captureLocation + imageHotspot("myImage"))

This will click at the hotspot location for the image assuming that nothing has changed position since your original capture. This is often a big “if”, which is why we don’t just use coordinates as the basis of our scripts. But your proposed approach would be no more reliable and a lot more effort.

Unless you are doing this because you know that the element has changed appearance (because of a version update or the like), you’re likely to just keep replacing one bad image with another. Often, when an image is changing for some reason, it is just shifting between two states, and you end up just constantly replacing one image when the other. If you suspect this is the case, you are better off adding an image to the command and having something like this:

clickAny "imageVersion1", "imageVersion2"

All that said, if you are sure that you want to try automatically capturing the original image area and replacing the current image with it, I can tell you how to do that. Let me know.

Matt,

Yes, I do want to automatically capture image and replace the old one. Please tell me how. I’m very appreciated.

Best Regards,

Currently this is as close as you can get to doing what you want:

if not imageFound(someimage) then
	put imageInfo(someimage) into imageProperties
	capturescreen imageProperties.imageName, (imageProperties.captureLocation, imageProperties.captureLocation + imageProperties.imagesize)
	Click imageProperties.hotspot
else
       Click foundImageLocation()
end if

However, there is a problem with this. For performance-related reasons, Eggplant has an image cache that is created when a suite is opened. Currently most changes made via the filesystem (which is what this script is doing) do not propagate back up to the image cache. So even though this script will replace the old image with a new screencapture on disk, you won’t see the new image and your script will continue to use the old, cached version of the image. And this will continue to be the case even when you run this script a second time – it still will not use the image that was captured on the previous run. The only remedy for this (currently) is to quit and relaunch Eggplant. So you might want to add a LogError or LogWarning message to the block of code where the recapture occurs so that you know that it happened, and you can then restart Eggplant if you want to.

One other issue is that images generated in this manner will default to the “Tolerant” search type and will have their hotspots located in the center of the image. There is currently no way to override this behavior via a script.

We’re looking at improving the management of the image cache so that it will respond to changes made at the file-system level. We are also considering giving the user more control over the image properties when performing a screen capture.

Thanks so much your valuable inputs.

Best Regards,

Oops. I had to make a correction to the code sample above. Please note that the capturescreen command should end with “imageProperties.imagesize”, not “imageProperties.hotspot”. I’ve edited that post so the code shown is now correct. Sorry for any trouble this might have caused you.

Matt,

Is there anyway that I could force a mouse click out of image range, and base on coordinator?

Best Regards,

You can click anywhere on the screen by simply providing the coordinates where you want to click. You can also click relative to an image location, either by setting the hotspot to a location outside the edges of the image, or by using coordinate math to determine a relative position.

The first method is often used if you have numerous identical form fields that have different text labels; since the form fields themselves are all the same, you need to use the labels to uniquely identify the one you want to script against. Select the image that you want to capture (in this example, a field label) and then hold down the command key and click where you want the event to be targeted (in this case, within the field). This will move the hotspot (the red cross) to the position you clicked on while leaving the capture area where it was. Now you can click the toolbar item for the action you want ( Click, DoubleClick, MoveTo, etc.) and save the image. You’ll see that the hotspot is not in the center of the image where it normally appears by default; it may or may not be visible at all in the image well, depending on how far from the image you set it.

The second method lets you specify points to click in an ad hoc manner. You can write a command like this:

Click imageLocation("someImage") + ( x, y ) 

The imageLocation() function returns an ( x, y ) point, so you can simply add an ( x, y ) value to it to target the event wherever you like.

It’s also possible to dynamically specify the hotspot location on a command-by-command basis; this is a variation on the first method of specifying the target coordinates. The hotspot coordinates are expressed relative to the upper-left corner of the image, so for example, if you want to click in the upper-left corner of an image, you can type:

Click (imagename: "myImage", hotspot: (0, 0))

Or to click 100 pixels below and 60 pixels to the left of the upper-left corner you can type:

Click (imagename: "myImage", hotspot: (-60, 100))

I hope this answers your question. Let me know if any of it is not clear to you.