Mouse Events and Control
This section describes the Eggplant Functional commands and functions that execute mouse events or return information about the mouse cursor on the SUT. Many of these commands and functions, including Click
, DoubleClick
, Drag
, Drop
, DragandDrop
, MouseButtonDown
, and MouseLocation()
, work against mobile SUTs as well as desktop SUTs, which is helpful when creating scripts that automate both mobile and desktop platforms. SenseTalk also includes a set of mobile commands and functions, a subset of which (Tap
, DoubleTap
, Press
, etc.) are compatible with desktop SUTs.
Click
Command
This code definition explains the use of the Click
command for image-based scripting. For information about using this command for WebDriver connections, see WebDriver Mouse and Keyboard Events: Click Command.
Behavior: Clicks the SUT mouse on the hot spot (Image) or center (OCR) of the first location found. If more than one image or text string is passed, Eggplant Functional searches for images in the order in which they are listed.
The Tap
and Click
commands perform the same event and can be used against both desktop and mobile SUTs.
Parameters: One or more Image References or Text Properties (for OCR), or a single coordinate location.
Example:
repeat with each item of ["Option1","Option2","Option3"] //Repeats through a list of images
click it//Clicks the hot spot of the current image in the list
end repeat
Example:
click{text:"Tweet",waitFor:10,searchRectangle:["AnchorLeft","AnchorRight"]} //Clicks the center of string "Tweet", waiting up to ~10 seconds for it to appear with the specified searchRectangle
Example:
Use code like this to select a section of items, such as files in File Explorer/Finder, and then copy the files
Click "FirstEntry" //Clicks the hot spot of image "FirstEntry"
KeyDown ShiftKey //Holds down the shift key
Click "LastEntry" //Clicks the hot spot of image "LastEntry"
KeyUp ShiftKey //Releases the shift key
RightClick //Right clicks at the same location as the previous mouse event
Click "CopyMenuItem"
Example:
Sometimes searching for an image twice, once before the click, is helpful when automating UIs that shift as their content loads
WaitFor 10, "NewTweet" //Waits for the image NewTweet to appear
Click{Image:"NewTweet",HotSpot:[80,0]} //Searches for NewTweet again and sends the click 80 pixels to the right of the image's upper left corner. Note the addition of the "image:" property when including the HotSpot image property
Example:
if ImageFound(text:"Cancel") then click FoundImageLocation() //Clicks the location of the center of the found string "Cancel"
Example:
Click the RemoteScreenSize*.5 //Clicks the center point of the screen
Example:
//Use code like this to perform a triple click event
on TripleClick imageToClick //Declares a custom command handler named "TripleClick" with parameter "imageToClick"
//The next 3 lines change the timing between Eggplant Functional commands so that 3 quick clicks can be sent in succession
put the RemoteWorkInterval into defaultRWI //Stores the current Remote Work Interval value so that it can be restored later
set the RemoteWorkInterval to .01 //Sets the RemoteWorkInterval to .01 seconds, allowing events to be sent to the SUT much more rapidly
//These 3 lines click the image once and then click twice more in the same location, at the interval specified by the RemoteWorkInterval
Click imagetoClick //Sends a click at the hot spot location of the image passed in as a parameter
//The subsequent 2 clicks occur at the same location as the previous click
Click
Click
set the RemoteWorkInterval to defaultRWI //Restores the RemoteWorkInterval to the original value
end TripleClick
DoubleClick
Command
This code definition explains the use of the DoubleClick
command for image-based scripting. For information about using this command for WebDriver connections, see WebDriver Mouse and Keyboard Events: DoubleClick Command.
Behavior: Double-clicks the SUT mouse on the hot spot (Image) or center (OCR) of the first location found. If more than one image or text string is passed, Eggplant Functional searches for images in the order in which they are listed.
The DoubleTap
and DoubleClick
commands perform the same event and can be used against both desktop and mobile SUTs.
Parameters: One or more Image References or Text Properties (for OCR), or a single coordinate location.
Example:
//Use code like this to scrape values from the SUT using the clipboard
doubleclick "ConfirmationNumber" //DoubleClicks the hot spot of image ConfirmatioNumber in order to highlight text on the SUT
typetext controlKey, "c" //Uses key strokes to perform the copy event on the SUT in order to put the highlighted text into the SUT clipboard
put the remoteClipboard into ConfNum //Retrieves the content of the SUT's clipboard and stores it in a variable
Example:
//This example is similar to the TripleClick example above, but uses a slightly different approach with DoubleClick as well as alternate syntax
to handle TripleClick //Declares a custom command handler named "TripleClick"
put the MouseDoubleClickDelay into clickTime //Stores the MouseDoubleClickDelay in variable clickTime for later use
set the RemoteWorkInterval to clickTime //Sets the RemoteWorkInterval, the interval between events sent to the SUT, to the value stored in clickTime
DoubleClick param(1) //DoubleClicks the first parameter value (image name, coordinate pair, etc.) passed to the TripleClick handler
Click//Clicks the same location as the previous DoubleClick
set the RemoteWorkInterval to .7 //Sets the RemoteWorkInterval to .7 second
end TripleClick
RightClick
Command
This code definition explains the use of the RightClick
command for image-based scripting. For information about using this command for WebDriver connections, see WebDriver Mouse and Keyboard Events: RightClick Command.
Behavior: Right-clicks the SUT mouse on the hot spot (Image) or center (OCR) of the first location found. If more than one image or text string is passed, Eggplant Functional searches for images in the order in which they are listed.
Parameters: One or more Image References or Text Properties (for OCR), or a single coordinate location.
Example:
RightClick {imageName: "Login", searchType: "smooth"} //Right-clicks the hot spot of image "Login", using the searchType:smooth image property for the image search. Note the addition of the "imageName:" property when including an image property.
Example:
rightClick text:"Firefox" //Right clicks at the center of string "Firefox"
moveTo text:"Send to" //Moves the mouse cursor to the center of string "Send to"
Example:
//Use code like this to select multiple items, such as files in File Explorer/Finder, and then copy the files
Click "FirstEntry" //Clicks the hot spot of image "FirstEntry"
KeyDown ControlKey //Holds down the control key
Click "LastEntry" //Clicks the hot spot of image "LastEntry"
KeyUp AllKeys //Releases any and all keys that might be down, including the control key
RightClick //Right clicks at the same location as the previous mouse event
Click "CopyMenuItem"