question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Move mouse to any point on screen with WinAppDriver

See original GitHub issue

I 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:

  1. 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();

  2. 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:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
DLightstonecommented, Aug 17, 2019

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.

0reactions
Shakevgcommented, Jun 7, 2021

Hi @HenryColes

I used next c# code to click by coordinates with WinappDriver:

var element = session.FindElement(By...); 
new Actions(session).MoveToElement(element, 0, 0).MoveByOffset(dx, dy).Click().Build().Perform();

To reset the mouse coordinates use this: new Actions(session).MoveToElement(element, 0, 0)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 9 - Mouse Actions - Test Automation University
moveToElement moves the mouse to the middle of the element. moveByOffset moves the mouse from its current position by the given offset in...
Read more >
Use WebDriverAPI.Mouse.MouseDownMoveUp in ...
Use the MouseDownMoveUp method in WebDriverAPI package in your next WinAppDriver project with LambdaTest Automation Testing Advisor.
Read more >
Actions MoveByOffset in Win App Driver: How can I see it ...
I have used Mouse.Move in CodedUI and Mouse.StartDragging etc and you can set the speed and see what they're doing and correct them...
Read more >
Moving mouse pointer to a specific location or element ...
We can move mouse pointer to a specific location or element in Selenium webdriver(C#) using the Actions class. We have to first create...
Read more >
WinAppDriver - Plains Wheeler
This is useful when you want to test keyboard shortcuts sent to the main window or when you have a need to move...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found