EzMouseFunctions

EzMouseFunctions is one of two hardware manipulation classes (the other being EzKeyboardFunctions) that will physically send mouse input to the application under test
💡 Note

Using this class will physically control your mouse. Be sure that you computer is in a state where you do not need to use it for anything else except automation

Syntax

        public static class EzMouseFunctions

Methods

Name Return Type Description
MoveMouse(EzElement element) void Moves the mouse to the center of the element passed in
MoveMouse(int x, int y) void Moves the mouse to the x/y coordinate passed in
LeftClick(EzElement element) void Performs a single left click on the clickable point of the element passed in
RightClick(EzElement element) void Performs a single right click on the clickable point of the element passed in
DoubleClick(EzElement element, int spacing = 500) void Performs a double click. The spacing int passed in will determine the length of time between click events. If nothing is passed, in the DoubleClickGap value in Config will be used instead
ScrollUp(EzElement element, uint wheelClicks = 1) void Performs a scroll in the upward direction based on the wheelClicks uint passed in
ScrollDown(EzElement element, uint wheelClicks = 1) void Performs a scroll in the downward direction based on the wheelClicks uint passed in

Samples and Usage

The EzMouseFunctions class will physically perform mouse events including mouse clicks, movements and scrollwheel actions

Sample:

        //Simple method to launch Windows' built in notepad application
        const string notepadPath = C:\\Windows\\System32\\notepad.exe";

        //Get an instance of EzProcess in order to create EzRoot.  Wrap it in a using statement to ensure that
        //.Dispose() is called
        using (EzProcess process = new EzProcess(notepadPath, "Notepad"))
        {
            process.StartProcess();

            //Get the root element of the application
            EzRoot root = new EzRoot(process);

            //Get both the menu bar and the text edit portion of the application
            EzElement menuBar = root.RootElement.FindChildByAutomationId("MenuBar");
            EzElement textEditor = root.RootElement.FindChildByName("Text Editor");

            //Get the file element by querying all children of the menuBar item for one named "File"
            EzElement fileElement = menuBar.FindChildByName("File");

            //Perform a left click on the fileElement.  This will expand the file slideout
            EzMouseFunctions.LeftClick(fileElement);

            //Sleep for 1 second
            Thread.Sleep(1000);

            //Right click in the main text editor
            EzMouseFunctions.RightClick(textEditor);
        }