Move mouse to any point on screen with WinAppDriver
See original GitHub issueI have automation test that run on client and WinAppDriver with my tested app on server.
With the session created from capability ‘app’ = ‘root’
var option = new AppiumOptions();
option.AddAdditionalCapability("app", "Root");
var session = new WinAppDriverSession<T>(new Uri(serviceUrl), option);
Now i want to move the mouse to a point on screen - even that point is out of my app’s window. Up to now, i have to do 2 steps:
-
move mouse to top left of screen with
-int.MaxValue
- looks ugly:Actions a = new Actions(session);
a.MoveByOffset(-int.MaxValue, -int.MaxValue);
a.Perform();
-
move mouse to the desire point:
a = new Actions(session);
a.MoveByOffset(myPoint.X, myPoint.Y);
a.Perform();
Because at the client, i have no idea how to get remote screen resolution or current mouse position. I cannot move the mouse to desire point with one action. Is there any better solution to get the same result? In my real scenario when i have thousands of automation test cases, the mouse move to top left of screen lot of times and looks silly.
Many thanks,
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top GitHub Comments
I do not know the reference for the position and size information provided by attribute retrieval. I have assumed them to be actual screen coordinates. I assumed move offset to be in actual screen coordinates rather than relative to the current application window.
I assumed that the positioning was to move was for purposes of either activating an application control located at that position or editing a pixel at that location. It became a question of - To position to a particular application pixel what absolute screen pixel is needed? That is a scaling problem.
I just wanted to get the locations of 2 application points (minimize button and maximize button were the first points I thought about. I completely forgot you could get the window size)
At start up of the program under test, maximize the screen (one time event), get the display screen size. It may be possible to get the display size via other means.
At any other time the then current application window size.
The 2 measurements give you the scaling info for the application window relative to the display screen.
Hi @HenryColes
I used next c# code to click by coordinates with WinappDriver:
To reset the mouse coordinates use this:
new Actions(session).MoveToElement(element, 0, 0)