Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

In Silk Test Workbench how can I move the mouse cursor relative to the desktop?

In Silk Test Workbench how can I move the mouse cursor relative to the desktop?

Typically if you want to move the mouse cursor in SilkTest, you would use a control as a basis for calculating the co-ordinates for the location of where the mouse is to be moved. For example the following  VB.Net sub routine demonstrates how I called the method “GetRect” against the “TreeView” dialog box shown below,  in order to return the coordinates for where I wish to move the mouse.

 

 

      Public Sub GetRectTest()

            Dim intNo As Integer = 0

            With _desktop.Window("@caption='Test Application'")

                  With .Dialog("@caption='Tree View'")

                        .SetActive()

                        myRect = .Tree("@caption='The Tree View'").GetRect()

                        .MouseMove(New Point(myRect.x,myRect.y))

                        While intNo <105

                              .MouseMove(New Point(myRect.x+25,myRect.y+IntNo))

                              .Click(MouseButton.Left, New Point(myRect.x+25,myRect.y+IntNo))

                              intNo = intNo +15

                        End While  

                  End With

            End With

      End Sub    

When the sub routine is executed it will move the mouse and then click on each of the “Tree”  elements; it does this by adding 25 pixels to the x coordinate for each iteration of the While loop.

  

 

However such scenarios may arise, where you are either not able to identify an object to call the GetRect() method against or you need to get the coordinates from the current mouse cursor position as it appears on the desktop. In such scenarios you will have to do the following in the SilkTest Workbench.

 

1)      Create a “New Application Configuration” for the Windows Desktop; this can be done by hooking the “Explorer.exe”

 

 

2)      Minimize all windows on the desktop, then from SilkTest Workbench start the “Identify Object”  tool to identify the Windows OS Desktop, like so:

 

 

3)      Use the “Cursor” class in .NET to return the current position of the cursor to the type “Point”. The VB.NET script below demonstrates how to do this:

 

Imports SilkTest.Ntf
Imports SilkTest.Ntf.Win32

 Public Module Main
 Dim _desktop As Desktop = Agent.Desktop

 Public Sub GetCursorFromDesktop()

            'Create new variable to hold the coordinates of type Point

            Dim cursorPosition As System.Drawing.Point

            Dim intNumber As Integer = 0

            'The code below is used to simply hover the mouse over a control so as
            'the mouse cursor is where I want it to be on the desktop for testing purposes

            With _desktop.Window("@caption='Test Application'")

            With .Dialog("@caption='Tree View'")

                        .SetActive()

                        .Tree("@caption='The Tree View'").MouseMove(New Point(20,5))

                        System.Threading.Thread.Sleep(2000)

                        'Get the current Cursor position on the desktop by calling the “Position” property

                        cursorPosition = System.Windows.Forms.Cursor.Position

                  End With

            End With

                  'Hook into the desktop so that the move mouse actions are performed
                  'relative to desktop as opposed to relative to a specific control or AUT

                  With _desktop.ListView("/Control[@caption='Program Manager']//ListView")

                        .MouseMove(New Point(cursorPosition.x,cursorPosition.y))

                        While intNumber <100

                              .MouseMove(New Point(cursorPosition.x+25,cursorPosition.y+intNumber))

                              .Click(MouseButton.Left, New Point(cursorPosition.x+25,cursorPosition.y+intNumber))

                              intNumber = intNumber +15

                        End While  

                  End With   

   End Sub          

       Public Sub Main()

            'Get the Sub routine
            GetCursorFromDesktop()

      End Sub

End Module

 

 

When executed, like the Sub routine “GetRectTest()” the code will iterate through each of the “Tree” Elements, however unlike that Sub routine, the cursor position used will be relative to the desktop and not the control identified as “Tree("@caption='The Tree View'")”

 

 

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-09-19 10:12
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.